Beispiel #1
0
//*****************************************************************************
//
//! initDriver
//!
//!  \param[in] cRequestPatch 0 to load with EEPROM patches 
//!             and 1 to load with no patches
//!
//!  \return none
//!
//!  \brief  The function initializes a CC3000 device 
//!          and triggers it to start operation
//
//*****************************************************************************
static int initDriver(unsigned short cRequestPatch)
{
    // WLAN On API Implementation
    wlan_init(CC3000_UsynchCallback, sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch,
              ReadWlanInterruptPin, SpiResumeSpi, SpiPauseSpi, WriteWlanPin);

    // Trigger a WLAN device
    wlan_start(cRequestPatch);
    wlan_smart_config_set_prefix((char*)aucCC3000_prefix);
    wlan_ioctl_set_connection_policy(0, 0, 0);
    wlan_ioctl_del_profile(255);

    // 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);

    //unsolicicted_events_timer_init();
    systick_sleep(100);
    return(0);
}
//*****************************************************************************
//
//! initDriver
//!
//!  \param[in] cRequestPatch 0 to load with EEPROM patches and 1 to load with no patches
//!
//!  \return none
//!
//!  \brief  The function initializes a CC3000 device and triggers it to start operation
//
//*****************************************************************************
int
initDriver(unsigned short cRequestPatch)
{
	

    //
	// Init GPIO's
	//
	pio_init();
	//
    //init all layers
    //
    init_spi();


	//
	// WLAN On API Implementation
	//
	wlan_init( CC3000_UsynchCallback, sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch, ReadWlanInterruptPin, WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin);
	//
	// Trigger a WLAN device
	//
	wlan_start(cRequestPatch);
  wlan_smart_config_set_prefix(aucCC3000_prefix);
	
	// Turn on the LED 5 to indicate that we are active and initiated WLAN successfully
     turnLedOn(5);

	//
	// 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);

        unsolicicted_events_timer_init();
    return(0);
}
Beispiel #3
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);
}
Beispiel #4
0
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));

}
/*******************************************************************************
 * 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;
}
//*****************************************************************************
//
//!  \brief returns a pointer to the RX buffer at the specific position
//!
//!  \param  pos is the location in the RX buffer to which pointer will point
//!
//!  \return a pointer to the RX UART buffer
//
//*****************************************************************************
void runUARTTerminal()
{
    char validPos = 0;
    char * ftcPrefixptr;
    
    if(uartRXByte(bytesInUart()-1) != '\b' && uartRXByte(bytesInUart()-1) != 0x7F)
    {
            sendByte(uartRXByte(bytesInUart()-1));
    }
    else
    {
        // Do backspace only if it doesn't erase '>'
        // Note that the backspace is itself in the buffer
        if(bytesInUart() > 1)
        {  
            // Echo Backspace and remove latest byte
            sendByte(uartRXByte(bytesInUart()-1));
            
            // Erase Backspace from buffer
            removeLastByteinBuf();
            
            // Erase last character
            removeLastByteinBuf();           
        }
        else
        {
            // Erase Backspace from buffer
            removeLastByteinBuf();
        }
    }
    
    
    switch(uartRXByte(bytesInUart()-1)) 
    {
    case '\r':
    case '\n':
        
        // Erase \r or \n from buffer
        removeLastByteinBuf();
        
        // Skip all non characters
        validPos = 0;
        while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart() )
            validPos++;
        
        // Process Command
        if(validPos <= bytesInUart())
        {
            sendString("\n");
            
            // help command
            if(checkCommand(uartRXBytePointer(validPos),"help") == 1)
            {
                printCommandList();
            }
            else if(checkCommand(uartRXBytePointer(validPos),"assoc") == 1)
            {                
                // Disable RX interrupt so it does not interfere
                // with GUI's command
                UCA1IE &= ~UCRXIE;
                
                validPos += strlen("assoc");
                while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart())
                    validPos++;
                
                *ptrSSIDInd = FLASH_FLAG_SET;
                memset((char *)ptrSSID, 0, MAX_SSID_LEN);
                memcpy(ptrSSID,uartRXBytePointer(validPos),MAX_SSID_LEN);
                
                sendString("OK\r\n");
                
                // If server is running, accept is blocking us. We can
                // therefore just restart the MSP430. Since the SSID indicator
                // has been set, at startup it will attempt to associate to the
                // AP requested by the user.
                if(currentCC3000State() & CC3000_SERVER_INIT)
                {  
                     terminalPrint("Restarting MSP430...\r\n");                  
                    restartMSP430();
                }
                else
                {
                    // Associate command
                	ConnectUsingSSID((char *)ptrSSID, (unsigned char *)ptrPASSPHRASE, (long)ptrSECURITY); //ConnectUsingSSID((char *)ptrSSID, (unsigned char *)ptrPASSPHRASE, (unsigned long)ptrSECURITY);
                }
                UCA1IE |= UCRXIE;                         // Enable RX interrupt
            }
            else if(checkCommand(uartRXBytePointer(validPos),"stat") == 1)
            {
                #ifdef    SENSOR_APP_VERSION
                    terminalPrint("Sensor App Version: ");
                    terminalPrint(SENSOR_APP_VERSION);
                    terminalPrint("\r\n");
                #endif
//#ifndef CC3000_TINY_DRIVER
//                printConnectionInfo(getCC3000Info());
//#endif
            }
            else if(checkCommand(uartRXBytePointer(validPos),"prfx") == 1)
            {
                // parameter sent with prfx should be 3 letters
                // that are the prefix. If they're not, we issue an error
                
                validPos += strlen("prfx");
                while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart() )
                    validPos++;
                
                if(validPos <= bytesInUart())
                {
                    // Verify letters
                    if(isUppercaseChar(uartRXByte(validPos)) && 
                       isUppercaseChar(uartRXByte(validPos+1)) && 
                       isUppercaseChar(uartRXByte(validPos+2)))
                    {
                        // Wait for 3 characters from UART
                        ftcPrefixptr = (char *)(&aucCC3000_prefix[0]);
                        *ftcPrefixptr = uartRXByte(validPos);
                        
                        ftcPrefixptr = (char *)(&aucCC3000_prefix[1]);
                        *ftcPrefixptr = uartRXByte(validPos+1);
                        
                        
                        ftcPrefixptr = (char *)(&aucCC3000_prefix[2]);
                        *ftcPrefixptr = uartRXByte(validPos+2);
                        
                        // Send new prefix to CC3000
                        wlan_smart_config_set_prefix((char *)aucCC3000_prefix);
                        
                        char prfStr[4];
                        prfStr[0] = aucCC3000_prefix[0];
                        prfStr[1] = aucCC3000_prefix[1];
                        prfStr[2] = aucCC3000_prefix[2];
                        prfStr[3] = '\0';
                        
                        //turnLedOff(CC3000_UNUSED1_IND);
                        sendString("\r\nSmart Config Prefix changed to: ");
                        sendString (prfStr);
                        sendString("\r\n");
                    }
                    else
                    {
                        sendString("Prefix Error");
                    }
                    
                }
                else
                {
                    sendString("Prefix Error");   
                }                        
            }
            else
            {
                sendString("Invalid or incomplete command. Type help for command list");
            }
        }
        
        // Send '>'
        sendString("\r\n> ");
        resetUARTBuffer();
        break;
        
    }
}
/**
 * @brief Begins SmartConfig. The user needs to run the SmartConfig phone app.
 *
 * @param[in] timeout optional time (ms) to wait before stopping. 0 = no timeout
 * @return True if connected to wireless network. False otherwise.
 */
bool SFE_CC3000::startSmartConfig(unsigned int timeout)
{
    char cc3000_prefix[] = {'T', 'T', 'T'};
    unsigned long time;
    
    /* Reset all global connection variables */
    ulSmartConfigFinished = 0;
	ulCC3000Connected = 0;
	ulCC3000DHCP = 0;
	OkToDoShutDown=0;
    
    /* If CC3000 is not initialized, return false. */
	if (!getInitStatus()) {
        return false;
    }
    
    /* Set connection profile to manual (no fast or auto connect) */
    if (wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE) != 
                                                            CC3000_SUCCESS) {
        return false;
    }
    
    /* Delete old connection profiles */
    if (wlan_ioctl_del_profile(255) != CC3000_SUCCESS) {
        return false;
    }
    
    /* Wait until CC3000 is disconnected */
    while (getConnectionStatus()) {
        delay(1);
    }
    
    /* Sets the prefix for SmartConfig. Should always be "TTT" */
    if (wlan_smart_config_set_prefix((char*)cc3000_prefix) != CC3000_SUCCESS) {
        return false;
    }
    
    /* Start the SmartConfig process */
    if (wlan_smart_config_start(0) != CC3000_SUCCESS) {
        return false;
    }
    
    /* Wait for SmartConfig to complete */
    time = millis();
    while (ulSmartConfigFinished == 0) {
        if (timeout != 0) {
            if ( (millis() - time) > timeout ) {
                return false;
            }
        }
    }
    
    /* Configure to connect automatically to AP from SmartConfig process */
    if (wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE) != 
                                                            CC3000_SUCCESS) {
        return false;
    }
    
    /* Reset CC3000 */
    wlan_stop();
    delay(400);
    wlan_start(0);
    
    /* Wait for connection and DHCP-assigned IP address */
    while (getDHCPStatus() == false) {
        if (timeout != 0) {
            if ( (millis() - time) > timeout ) {
                return false;
            }
        }
    }
    
    /* If we make it this far, we need to tell the SmartConfig app to stop */
    mdnsAdvertiser(1, DEVICE_NAME, strlen(DEVICE_NAME));
    
    /* Get connection information */
    netapp_ipconfig(&connection_info_);

    return true;
}
Beispiel #8
0
void StartSmartConfig(void)
{
  long rval;

  if (!isInitialized)
    {
      printf("CC3000 not initialized; can't run Smart Config.\n");
      return;
    }

  printf("Starting Smart Config\n");

  printf("  Disabling auto-connect policy...");
  if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE)) !=0)
    {
      printf(" Failed!\n    Setting auto connection policy failed, error: %lx\n",
             (unsigned long)rval);
      return;
    }

  printf(" Succeed\n");
  printf("  Deleting all existing profiles...");
  fflush(stdout);

  if ((rval = wlan_ioctl_del_profile(255)) !=0)
    {
      printf(" Failed!\n    Deleting all profiles failed, error: %lx\n",
             (unsigned long)rval);
      return;
    }

  printf(" Succeed\n");
  wait_on(20*MS_PER_SEC, &ulCC3000Connected, 0, "  Waiting until disconnected");

  printf("  Setting smart config prefix...");
  fflush(stdout);

  if ((rval = wlan_smart_config_set_prefix(simpleConfigPrefix)) !=0)
    {
      printf(" Failed!\n    Setting smart config prefix failed, error: %lx",
             (unsigned long)rval);
      return;
    }

  printf(" Succeed\n");
  printf("  Starting smart config...");
  fflush(stdout);

  if ((rval = wlan_smart_config_start(0)) !=0)
    {
      printf(" Failed!\n    Starting smart config failed, error: %lx\n",
             (unsigned long)rval);
      return;
    }

  printf(" Succeed\n");

  if (!wait_on(30*MS_PER_SEC, &ulSmartConfigFinished, 1, "  Waiting on Starting smart config done"))
    {
      printf("    Timed out waiting for Smart Config to finish. Hopefully it did anyway\n");
    }

  printf("  Smart Config packet %s!\n",ulSmartConfigFinished ? "seen" : "NOT seen");

  printf("  Enabling auto-connect policy...");
  fflush(stdout);

  if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE)) !=0)
    {
      printf(" Failed!\n    Setting auto connection policy failed, error: %lx\n",
             (unsigned long)rval);
      return;
    }

  printf(" Succeed\n");
  printf("  Stopping CC3000...\n");
  fflush(stdout);
  wlan_stop();  /* No error returned here, so nothing to check */

  printf("  Pausing for 2 seconds...\n");
  sleep(2);

  printf("  Restarting CC3000... \n");
  wlan_start(0);  /* No error returned here, so nothing to check */

  if (!wait_on(20*MS_PER_SEC, &ulCC3000Connected, 1, "  Waiting for connection to AP"))
    {
      printf("    Timed out waiting for connection to AP\n");
      return;
    }

  if (!wait_on(15*MS_PER_SEC, &ulCC3000DHCP, 1, "  Waiting for IP address from DHCP"))
    {
      printf("    Timed out waiting for IP address from DHCP\n");
      return;
    }

  printf("  Sending mDNS broadcast to signal we're done with Smart Config...\n");
  fflush(stdout);

  /* The API documentation says mdnsAdvertiser() is supposed to return 0 on
   * success and SOC_ERROR on failure, but it looks like what it actually
   * returns is the socket number it used. So we ignore it.
   */

  mdnsadvertiser(1, device_name, strlen(device_name));

  printf("  Smart Config finished Successfully!\n");
  ShowInformation();
  fflush(stdout);
}
/*------------------------------------------------------------------------
  
  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;
}
Beispiel #10
0
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);
}
Beispiel #11
0
void StartSmartConfig(void)
{

  ulSmartConfigFinished = 0;
  ulCC3000Connected = 0;
  ulCC3000DHCP = 0;
  OkToDoShutDown=0;

  // Reset all the previous configuration

  if (wlan_ioctl_set_connection_policy(0, 0, 0) != 0) {
    digitalWrite(ErrorLED, HIGH);
    return;
  }

  if (wlan_ioctl_del_profile(255) != 0) {
    digitalWrite(ErrorLED, HIGH);
    return;
  }

  //Wait until CC3000 is disconnected
  while (ulCC3000Connected == 1)
  {
    delayMicroseconds(100);
  }

  // Serial.println("waiting for disconnect");

  // Trigger the Smart Config process
  // Start blinking LED6 during Smart Configuration process
  digitalWrite(ConnLED, HIGH);  
  
  if (wlan_smart_config_set_prefix((char*)aucCC3000_prefix) != 0){
    digitalWrite(ErrorLED, HIGH);
    return;
  }

  digitalWrite(ConnLED, LOW);

  // Start the SmartConfig start process
  if (wlan_smart_config_start(0) != 0){
    digitalWrite(ErrorLED, HIGH);
    return;
  }
  if (DEBUG_MODE) {
    Serial.println("smart config start");
  }

  digitalWrite(ConnLED, HIGH);
  
  // Wait for Smartconfig process complete
  while (ulSmartConfigFinished == 0)
  {
    delay(500);
    digitalWrite(ConnLED, LOW);
    delay(500);
    digitalWrite(ConnLED, HIGH);
  }
  
  if (DEBUG_MODE) {
    Serial.println("smart config finished");
  }
  digitalWrite(ConnLED, LOW);

  
  // Configure to connect automatically to the AP retrieved in the 
  // Smart config process. Enabled fast connect.
  if (wlan_ioctl_set_connection_policy(0, 0, 1) != 0){
    digitalWrite(ErrorLED, HIGH);
    return;
  }
  
  // reset the CC3000
  wlan_stop();

  delayMicroseconds(500);
  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);
  if (DEBUG_MODE) {
    Serial.print("Config done");
  }
}