コード例 #1
0
void StartSmartConfig(void)
{
	ulSmartConfigFinished = 0;
	ulCC3000Connected = 0;
	ulCC3000DHCP = 0;
	OkToDoShutDown=0;
	
	// Reset all the previous configuration
	wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);	
	wlan_ioctl_del_profile(255);
	
	//Wait until CC3000 is disconnected
	while (ulCC3000Connected == 1)
	{
		SysCtlDelay(100);
		hci_unsolicited_event_handler();
	}
	
	// Start blinking LED1 during Smart Configuration process
	turnLedOn(1);
	
	wlan_smart_config_set_prefix((char*)aucCC3000_prefix);
	turnLedOff(1);		
	
	// Start the SmartConfig start process
	wlan_smart_config_start(1);
	turnLedOn(1);       
	
	// Wait for Smart config to finish
	while (ulSmartConfigFinished == 0)
	{
		turnLedOff(1);
		SysCtlDelay(16500000);
		turnLedOn(1);		  
		SysCtlDelay(16500000);
	}
	turnLedOn(1);	
	// create new entry for AES encryption key
	nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16);
	
	// write AES key to NVMEM
	aes_write_key((unsigned char *)(&smartconfigkey[0]));
	
	// Decrypt configuration information and add profile
	wlan_smart_config_process();
	
	// Configure to connect automatically to the AP retrieved in the 
	// Smart config process
	wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE);
	
	
	// reset the CC3000
	wlan_stop();
	
	DispatcherUartSendPacket((unsigned char*)pucUARTCommandSmartConfigDoneString,
													 sizeof(pucUARTCommandSmartConfigDoneString));
	
	SysCtlDelay(100000);
	wlan_start(0);	
	
	// Mask out all non-required events
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|
											HCI_EVNT_WLAN_ASYNC_PING_REPORT);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: vpcola/NucleoCC3K
static void cmd_smart_cc3000(BaseSequentialStream *chp, int argc, char *argv[])
{
    long rval;

    (void)argv;
    if(argc > 0)
    {
        chprintf(chp, "Usage: setup\r\n");
        return;
    }

    chprintf(chp, "Disconnecting ");
    wlan_disconnect();
    while(cc3000AsyncData.connected == 1)
    {
        chprintf(chp, ".");
    }
    chprintf(chp, "done!\r\n");

    chprintf(chp, "Disabling auto connect policy ...\r\n");
    /* Set connection policy to disable */
    if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE)) != 0)
    {
        chprintf(chp, "Error disabling auto connect policy ...\r\n");
        return;
    }

    /* Delete all profiles */
    chprintf(chp, "Deleting all profiles ...\r\n");
    if ((rval = wlan_ioctl_del_profile(255)) != 0)
    {
        chprintf(chp, "Error deleting profiles ...\r\n");
        return;
    }


    chprintf(chp, "Creating AES keys ...\r\n");
    nvmem_create_entry(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE);
    aes_write_key((UINT8 *) AES_KEY);

    // Set the smart config prefix
    chprintf(chp, "Setting smart config prefix ...\r\n");
    if((rval = wlan_smart_config_set_prefix(smartConfigPrefix)) != 0)
    {
        chprintf(chp, "Error setting smart config prefix ... \r\n");
        return;
    }
    chprintf(chp, "Starting CC3000 SmartConfig ...\r\n");
    if((rval = wlan_smart_config_start(0)) != 0)
    {
        chprintf(chp, "Error starting smart config ...\r\n");
        return;
    }

    chprintf(chp, "Waiting for SmartConfig to finish ...\r\n");
    /* Wait until smart config is finished */
    while(cc3000AsyncData.smartConfigFinished == 0)
    {
        // We blink the led here .. the thread process
        // will set this to PAL_LOW (since we are disconnected)
        palWritePad(CON_LED_PORT, CON_LED_PIN, PAL_HIGH);
        chThdSleep(MS2ST(200));
    }

    chprintf(chp, "Smart config packet received ...\r\n");
    /* Re enable auto connect policy */
    if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE)) != 0)
    {
        chprintf(chp, "Error setting auto connect policy ...\r\n");
        return;
    }

    /* Restart wlan */
    wlan_stop();
    chprintf(chp, "Reconnecting ...\r\n");
    chThdSleep(MS2ST(2000));
    wlan_start(0);
    /* No need to call connect, hopefully auto connect policy
     * can connect to our AP now
     **/
    chprintf(chp, "Waiting for connection to AP ...\r\n");
    while (cc3000AsyncData.dhcp.present != 1)
    {
        chThdSleep(MS2ST(5));
    }

    show_cc3_dhcp_info(chp);
    mdnsAdvertiser(1, deviceName, strlen(deviceName));

}
コード例 #3
0
void SPARK_WLAN_Setup(void (*presence_announcement_callback)(void))
{
	announce_presence = presence_announcement_callback;

	/* Initialize CC3000's CS, EN and INT pins to their default states */
	CC3000_WIFI_Init();

	/* Configure & initialize CC3000 SPI_DMA Interface */
	CC3000_SPI_DMA_Init();

	/* WLAN On API Implementation */
	wlan_init(WLAN_Async_Callback, WLAN_Firmware_Patch, WLAN_Driver_Patch, WLAN_BootLoader_Patch,
				CC3000_Read_Interrupt_Pin, CC3000_Interrupt_Enable, CC3000_Interrupt_Disable, CC3000_Write_Enable_Pin);

	Delay(100);

	/* Trigger a WLAN device */
	wlan_start(0);

	SPARK_LED_FADE = 0;

	SPARK_WLAN_STARTED = 1;

	/* Mask out all non-required events from CC3000 */
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE | HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_ASYNC_PING_REPORT);

	if(NVMEM_SPARK_Reset_SysFlag == 0x0001 || nvmem_read(NVMEM_SPARK_FILE_ID, NVMEM_SPARK_FILE_SIZE, 0, NVMEM_Spark_File_Data) != NVMEM_SPARK_FILE_SIZE)
	{
		/* Delete all previously stored wlan profiles */
		wlan_ioctl_del_profile(255);

		/* Create new entry for Spark File in CC3000 EEPROM */
		nvmem_create_entry(NVMEM_SPARK_FILE_ID, NVMEM_SPARK_FILE_SIZE);

		memset(NVMEM_Spark_File_Data,0, arraySize(NVMEM_Spark_File_Data));

		nvmem_write(NVMEM_SPARK_FILE_ID, NVMEM_SPARK_FILE_SIZE, 0, NVMEM_Spark_File_Data);

		NVMEM_SPARK_Reset_SysFlag = 0x0000;
		Save_SystemFlags();
	}

	if(WLAN_MANUAL_CONNECT == 0)
	{
		if(NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET] == 0)
		{
			WLAN_SMART_CONFIG_START = 1;
		}
		else if(NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET] == 0)
		{
			wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE);

			NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET] = 1;
			nvmem_write(NVMEM_SPARK_FILE_ID, 1, WLAN_POLICY_FILE_OFFSET, &NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET]);
		}
	}

	if((WLAN_MANUAL_CONNECT > 0) || !WLAN_SMART_CONFIG_START)
	{
		LED_SetRGBColor(RGB_COLOR_GREEN);
		LED_On(LED_RGB);
	}

	nvmem_read_sp_version(patchVer);
	if (patchVer[1] == 24)//19 for old patch
	{
		/* Latest Patch Available after flashing "cc3000-patch-programmer.bin" */
	}

	Clear_NetApp_Dhcp();

	Set_NetApp_Timeout();
}
コード例 #4
0
/*******************************************************************************
 * Function Name  : Start_Smart_Config.
 * Description    : The function triggers a smart configuration process on CC3000.
 * Input          : None.
 * Output         : None.
 * Return         : None.
 *******************************************************************************/
void Start_Smart_Config(void)
{
	WLAN_SMART_CONFIG_FINISHED = 0;
	WLAN_SMART_CONFIG_STOP = 0;
	WLAN_SERIAL_CONFIG_DONE = 0;
	WLAN_CONNECTED = 0;
	WLAN_DHCP = 0;
	WLAN_CAN_SHUTDOWN = 0;

	SPARK_SOCKET_CONNECTED = 0;
	SPARK_HANDSHAKE_COMPLETED = 0;
	SPARK_FLASH_UPDATE = 0;
	SPARK_LED_FADE = 0;

	LED_SetRGBColor(RGB_COLOR_BLUE);
	LED_On(LED_RGB);

	/* Reset all the previous configuration */
	wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);

	NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET] = 0;
	nvmem_write(NVMEM_SPARK_FILE_ID, 1, WLAN_POLICY_FILE_OFFSET, &NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET]);

	/* Wait until CC3000 is disconnected */
	while (WLAN_CONNECTED == 1)
	{
		//Delay 100ms
		Delay(100);
		hci_unsolicited_event_handler();
	}

	/* Create new entry for AES encryption key */
	nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16);

	/* Write AES key to NVMEM */
	aes_write_key((unsigned char *)(&smartconfigkey[0]));

	wlan_smart_config_set_prefix((char*)aucCC3000_prefix);

	/* Start the SmartConfig start process */
	wlan_smart_config_start(1);

	WiFiCredentialsReader wifi_creds_reader(wifi_add_profile_callback);

	/* Wait for SmartConfig/SerialConfig to finish */
	while (!(WLAN_SMART_CONFIG_FINISHED | WLAN_SERIAL_CONFIG_DONE))
	{
		if(WLAN_DELETE_PROFILES && wlan_ioctl_del_profile(255) == 0)
		{
			int toggle = 25;
			while(toggle--)
			{
				LED_Toggle(LED_RGB);
				Delay(50);
			}
			NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET] = 0;
			nvmem_write(NVMEM_SPARK_FILE_ID, 1, WLAN_PROFILE_FILE_OFFSET, &NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET]);
			WLAN_DELETE_PROFILES = 0;
		}
		else
		{
			LED_Toggle(LED_RGB);
			Delay(250);
			wifi_creds_reader.read();
		}
	}

	LED_On(LED_RGB);

	/* read count of wlan profiles stored */
	nvmem_read(NVMEM_SPARK_FILE_ID, 1, WLAN_PROFILE_FILE_OFFSET, &NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET]);

//	if(NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET] >= 7)
//	{
//		if(wlan_ioctl_del_profile(255) == 0)
//			NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET] = 0;
//	}

	if(WLAN_SMART_CONFIG_FINISHED)
	{
		/* Decrypt configuration information and add profile */
		wlan_profile_index = wlan_smart_config_process();
	}

	if(wlan_profile_index != -1)
	{
		NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET] = wlan_profile_index + 1;
	}

	/* write count of wlan profiles stored */
	nvmem_write(NVMEM_SPARK_FILE_ID, 1, WLAN_PROFILE_FILE_OFFSET, &NVMEM_Spark_File_Data[WLAN_PROFILE_FILE_OFFSET]);

	/* Configure to connect automatically to the AP retrieved in the Smart config process */
	wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE);

	NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET] = 1;
	nvmem_write(NVMEM_SPARK_FILE_ID, 1, WLAN_POLICY_FILE_OFFSET, &NVMEM_Spark_File_Data[WLAN_POLICY_FILE_OFFSET]);

	/* Reset the CC3000 */
	wlan_stop();

	Delay(100);

	wlan_start(0);

	SPARK_WLAN_STARTED = 1;

	/* Mask out all non-required events */
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE | HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_ASYNC_PING_REPORT);

    LED_SetRGBColor(RGB_COLOR_GREEN);
	LED_On(LED_RGB);

	Set_NetApp_Timeout();

	WLAN_SMART_CONFIG_START = 0;
}
コード例 #5
0
/*------------------------------------------------------------------------
  
  Spider_SmartConfig
  Use Smart config function set Spider connect to a exist AP.
  
  return  0, Connect success.
-----------------------------------------------------------------------*/
int Spider_SmartConfig(void){
    SmartConfigFinished = 0;
    SpiderConnected = 0;
    SpiderDHCP = 0;
    SpiderCanShutDown = 0;

    // Reset all the previous configuration
    wlan_ioctl_set_connection_policy(0, 0, 0);
    wlan_ioctl_del_profile(255);

    //Wait until Spider is disconnected
    while (SpiderConnected == 1){
        delay(1);
        hci_unsolicited_event_handler();
    }

    // create new entry for AES encryption key
    nvmem_create_entry(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE);

    // write AES key to NVMEM
    aes_write_key((unsigned char *)(&SmartConfig_key[0]));

    // Start blinking LED1 during Smart Configuration process
    digitalWrite(13, HIGH);
    wlan_smart_config_set_prefix((char*)SmartConfig_prefix);
    digitalWrite(13, LOW);

    // Start the SmartConfig start process
    if(wlan_smart_config_start(0) != 0){
      return -1;
    }

    // Wait for Smart config to finish
    while (SmartConfigFinished == 0){
        digitalWrite(13, HIGH);
        delay(500);
        digitalWrite(13, LOW);
        delay(500);
    }
    digitalWrite(13, LOW);


    // Decrypt configuration information and add profile
    //wlan_smart_config_process();

#if 1
    // Configure to connect automatically to the AP retrieved in the
    // Smart config process
    wlan_ioctl_set_connection_policy(0, 0, 1);

    // reset the CC3000
    wlan_stop();

    delay(100);

    wlan_start(0);

    // Set CC3000 event masking, right now without ping report.
    wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT);

#endif

    return 0;
}
コード例 #6
0
ファイル: cc3000.c プロジェクト: ianjuch/ee149
void StartSmartConfig(void)
{

	// Reset all the previous configuration
	//
	wlan_ioctl_set_connection_policy(0, 0, 0);	
        wlan_ioctl_del_profile(255);
	
	//Wait until CC3000 is dissconected
	while (ulCC3000Connected == 1)
	{
	  __delay_cycles(100);
    }

	// Start blinking LED6 during Smart Configuration process
	turnLedOn(LED6);
	wlan_smart_config_set_prefix(aucCC3000_prefix);
	//wlan_first_time_config_set_prefix(aucCC3000_prefix);
	turnLedOff(LED6);
	
    // Start the SmartConfig start process
	wlan_smart_config_start(1);
    turnLedOn(LED6);
	
	//
	// Wait for Smart config finished
	// 
	while (ulSmartConfigFinished == 0)
	{
		__delay_cycles(6000000);
                                                                             
		turnLedOn(LED6);

		__delay_cycles(6000000);
                
		turnLedOff(LED6);
	}

	turnLedOff(LED6);

    // create new entry for AES encryption key
	nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16);
	
	// write AES key to NVMEM
	aes_write_key((unsigned char *)(&smartconfigkey[0]));
	
	// Decrypt configuration information and add profile
	wlan_smart_config_process();
        
	//
	// Configure to connect automatically to the AP retrieved in the 
	// Smart config process
	//
	wlan_ioctl_set_connection_policy(0, 0, 1);
	
	//
	// reset the CC3000
	// 
	wlan_stop();
	__delay_cycles(600000);
	wlan_start(0);

	ConnectUsingSmartConfig = 1; 
        ulSmartConfigFinished = 0;
	//
	// Mask out all non-required events
	//
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT);
}