//*****************************************************************************
//
//! fat_read_content
//!
//! \param[out] is_allocated  array of is_allocated in FAT table:\n
//!						 an allocated entry implies the address and length of the file are valid.
//!  		    			 0: not allocated; 1: allocated.
//! \param[out] is_valid  array of is_valid in FAT table:\n
//!						 a valid entry implies the content of the file is relevant.
//!  		    			 0: not valid; 1: valid.
//! \param[out] write_protected  array of write_protected in FAT table:\n
//!						 a write protected entry implies it is not possible to write into this entry.
//!  		    			 0: not protected; 1: protected.
//! \param[out] file_address  array of file address in FAT table:\n
//!						 this is the absolute address of the file in the EEPROM.
//! \param[out] file_length  array of file length in FAT table:\n
//!						 this is the upper limit of the file size in the EEPROM.
//!
//! \return on succes 0, error otherwise
//!
//! \brief  parse the FAT table from eeprom 
//
//*****************************************************************************
unsigned char fat_read_content(unsigned char *is_allocated,
                               unsigned char *is_valid,
                               unsigned char *write_protected,
                               unsigned short *file_address,
                               unsigned short *file_length)
{
        unsigned short  index;
        unsigned char   ucStatus;
        unsigned char   fatTable[48];
        unsigned char*  fatTablePtr = fatTable;
        
        // read in 6 parts to work with tiny driver
        for (index = 0; index < 6; index++)
        {
          ucStatus = nvmem_read(16, 8, 4 + 8*index, fatTablePtr); 
          fatTablePtr += 8;
        }
        
        fatTablePtr = fatTable;
        
        for (index = 0; index <= NVMEM_RM_FILEID; index++)
        {
            *is_allocated++ = (*fatTablePtr) & BIT0;
            *is_valid++ = ((*fatTablePtr) & BIT1) >> 1;
            *write_protected++ = ((*fatTablePtr) & BIT2) >> 2;
            *file_address++ = (*(fatTablePtr+1)<<8) | (*fatTablePtr) & (BIT4|BIT5|BIT6|BIT7);
            *file_length++ = (*(fatTablePtr+3)<<8) | (*(fatTablePtr+2)) & (BIT4|BIT5|BIT6|BIT7);
            
            fatTablePtr += 4;  // move to next file ID
        }
        
        return ucStatus;
}
Ejemplo n.º 2
0
/*****************************************************************************
*
*   exoHAL_ReadUUID
*
*   \param  Interface Number (1 - WiFi), buffer to return hexadecimal MAC
*
*   \return 0 if failure; length of UUID if success;
*
*   \brief  Reads the MAC address from the hardware
*
*****************************************************************************/
int
exoHAL_ReadUUID(unsigned char if_nbr, unsigned char * UUID_buf)
{
  int retval = 0;

  #ifdef EN_COM_CONFIG
  	  const char hex[12];
  	  memcpy((char*)hex, passMAC, 12);
  #endif
  #ifndef EN_COM_CONFIG
  	  const char hex[] = "08002857f2ec";	// HARDCODED - MAC Address
  #endif

  unsigned char macBuf[10];

  switch (if_nbr) {
    case IF_GPRS:
      break;
    case IF_ENET:
      break;
    case IF_WIFI:
		#ifndef EN_ADS1118
    	nvmem_read(NVMEM_MAC_FILEID, 6, 0, (unsigned char *)macBuf);
		#endif

      UUID_buf[0]  = hex[macBuf[0] >> 4];
      UUID_buf[1]  = hex[macBuf[0] & 15];
      UUID_buf[2]  = hex[macBuf[1] >> 4];
      UUID_buf[3]  = hex[macBuf[1] & 15];
      UUID_buf[4]  = hex[macBuf[2] >> 4];
      UUID_buf[5]  = hex[macBuf[2] & 15];
      UUID_buf[6]  = hex[macBuf[3] >> 4];
      UUID_buf[7]  = hex[macBuf[3] & 15];
      UUID_buf[8]  = hex[macBuf[4] >> 4];
      UUID_buf[9]  = hex[macBuf[4] & 15];
      UUID_buf[10] = hex[macBuf[5] >> 4];
      UUID_buf[11] = hex[macBuf[5] & 15];

      UUID_buf[12] = 0;

      retval = strlen((char *)UUID_buf);
      if (retval == 0)
      {
    	  retval = 12;
      }
      break;
    default:
      break;
  }

  return retval;
}
Ejemplo n.º 3
0
/*
 * Read a chunk of NV memory
 */
void _plat__NvMemoryRead(unsigned int startOffset,
				    unsigned int size,
				    void *data)
{
	assert(startOffset + size <= NV_MEMORY_SIZE);
	/* Copy the data from the NV image */
#ifdef CONFIG_FLASH_NVMEM
	nvmem_read(startOffset, size, data, NVMEM_TPM);
#else
	memcpy(data, &s_NV[startOffset], size);
#endif
	return;
}
Ejemplo n.º 4
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();
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
BOOL cc3000_getMacAddress(uint8_t* macAddress) {
  return nvmem_read(NVMEM_MAC_FILEID, 6, 0, macAddress) == CC3000_SUCCESS;
}
Ejemplo n.º 7
0
unsigned char nvmem_get_mac_address(unsigned char *mac)
{
	return  nvmem_read(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac);
}
Ejemplo n.º 8
0
UINT8 nvmem_get_mac_address(UINT8 *mac)
{
	return  nvmem_read(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac);
}
Ejemplo n.º 9
0
long
wlan_smart_config_process()
{
    signed long	returnValue;
    unsigned long ssidLen, keyLen;
    unsigned char *decKeyPtr;
    unsigned char *ssidPtr;

    // read the key from EEPROM - fileID 12
    returnValue = aes_read_key(key);

    if (returnValue != 0)
        return returnValue;

    // read the received data from fileID #13 and parse it according to the followings:
    // 1) SSID LEN - not encrypted
    // 2) SSID - not encrypted
    // 3) KEY LEN - not encrypted. always 32 bytes long
    // 4) Security type - not encrypted
    // 5) KEY - encrypted together with true key length as the first byte in KEY
    //	 to elaborate, there are two corner cases:
    //		1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length
    //		2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31
    returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray);

    if (returnValue != 0)
        return returnValue;

    ssidPtr = &profileArray[1];

    ssidLen = profileArray[0];

    decKeyPtr = &profileArray[profileArray[0] + 3];

    aes_decrypt(decKeyPtr, key);
    if (profileArray[profileArray[0] + 1] > 16)
        aes_decrypt((unsigned char *)(decKeyPtr + 16), key);

    if (*(unsigned char *)(decKeyPtr +31) != 0)
    {
        if (*decKeyPtr == 31)
        {
            keyLen = 31;
            decKeyPtr++;
        }
        else
        {
            keyLen = 32;
        }
    }
    else
    {
        keyLen = *decKeyPtr;
        decKeyPtr++;
    }

    // add a profile
    switch (profileArray[profileArray[0] + 2])
    {
    case WLAN_SEC_UNSEC://None
    {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], 	// security type
                                       ssidPtr,		 					// SSID
                                       ssidLen, 							// SSID length
                                       NULL, 							// BSSID
                                       1,								// Priority
                                       0, 0, 0, 0, 0);

        break;
    }

    case WLAN_SEC_WEP://WEP
    {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], 	// security type
                                       ssidPtr, 							// SSID
                                       ssidLen, 							// SSID length
                                       NULL, 							// BSSID
                                       1,								// Priority
                                       keyLen,							// KEY length
                                       0, 								// KEY index
                                       0,
                                       decKeyPtr,						// KEY
                                       0);

        break;
    }

    case WLAN_SEC_WPA://WPA
    case WLAN_SEC_WPA2://WPA2
    {
        returnValue = wlan_add_profile(WLAN_SEC_WPA2, 	// security type
                                       ssidPtr,
                                       ssidLen,
                                       NULL, 							// BSSID
                                       1,								// Priority
                                       0x18,							// PairwiseCipher
                                       0x1e, 							// GroupCipher
                                       2,								// KEY management
                                       decKeyPtr,						// KEY
                                       keyLen);							// KEY length

        break;
    }
    }

    return returnValue;
}
Ejemplo n.º 10
0
long wlan_smart_config_process()
{
  signed long  returnValue;
  unsigned long ssidLen, keyLen;
  uint8_t *decKeyPtr;
  uint8_t *ssidPtr;

  /* Read the key from EEPROM - fileID 12 */

  returnValue = aes_read_key(akey);

  if (returnValue != 0)
    {
      return returnValue;
    }

  /* Read the received data from fileID #13 and parse it according to the followings:
   * 1) SSID LEN - not encrypted
   * 2) SSID - not encrypted
   * 3) KEY LEN - not encrypted. always 32 bytes long
   * 4) Security type - not encrypted
   * 5) KEY - encrypted together with true key length as the first byte in KEY
   *   to elaborate, there are two corner cases:
   *   1) the KEY is 32 bytes long. In this case, the first byte does not represent
   *      KEY length
   *   2) the KEY is 31 bytes long. In this case, the first byte represent KEY
   *      length and equals 31
   */

  returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE,
                           0, profileArray);

  if (returnValue != 0)
    {
      return returnValue;
    }

  ssidPtr = &profileArray[1];

  ssidLen = profileArray[0];

  decKeyPtr = &profileArray[profileArray[0] + 3];

  aes_decrypt(decKeyPtr, akey);
  if (profileArray[profileArray[0] + 1] > 16)
    {
      aes_decrypt((uint8_t *)(decKeyPtr + 16), akey);
    }

  if (*(uint8_t *)(decKeyPtr +31) != 0)
    {
      if (*decKeyPtr == 31)
      {
        keyLen = 31;
        decKeyPtr++;
      }
    else
      {
        keyLen = 32;
      }
    }
  else
    {
      keyLen = *decKeyPtr;
      decKeyPtr++;
    }

  /* Add a profile */

  switch (profileArray[profileArray[0] + 2])
    {
    case WLAN_SEC_UNSEC: /* None */
       {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], /* Security type */
                                       ssidPtr,          /* SSID */
                                       ssidLen,          /* SSID length */
                                       NULL,             /* BSSID */
                                       1,                /* Priority */
                                       0, 0, 0, 0, 0);
        break;
       }

    case WLAN_SEC_WEP: /* WEP */
      {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], /* Security type */
                                       ssidPtr,          /* SSID */
                                       ssidLen,          /* SSID length */
                                       NULL,             /* BSSID */
                                       1,                /* Priority */
                                       keyLen,           /* KEY length */
                                       0,                /* KEY index */
                                       0,
                                       decKeyPtr,        /* KEY */
                                       0);
        break;
      }

    case WLAN_SEC_WPA:  /* WPA */
    case WLAN_SEC_WPA2: /* WPA2 */
      {
        returnValue = wlan_add_profile(WLAN_SEC_WPA2,    /* Security type */
                                       ssidPtr,
                                       ssidLen,
                                       NULL,             /* BSSID */
                                       1,                /* Priority */
                                       0x18,             /* PairwiseCipher */
                                       0x1e,             /* GroupCipher */
                                       2,                /* KEY management */
                                       decKeyPtr,        /* KEY */
                                      keyLen);           /* KEY length */
        break;
      }
    }

  return returnValue;
}
Ejemplo n.º 11
0
uint8_t nvmem_get_mac_address(uint8_t *mac)
{
  return  nvmem_read(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac);
}
Ejemplo n.º 12
0
void patch_prog_start()
{
    unsigned short  index;
    unsigned char   *pRMParams;

    printf("Initializing module...\n");

    // Init module and request to load with no patches.
    // This is in order to overwrite restrictions to
    // write to specific places in EEPROM.
    initDriver(1);

    // Read MAC address.
    mac_status = nvmem_get_mac_address(cMacFromEeprom);

    return_status = 1;

    printf("Reading RM parameters...\n");
    while ((return_status) && (counter < 3)) {
        // Read RM parameters.
        // Read in 16 parts to work with tiny driver.
        return_status = 0;
        pRMParams = cRMParamsFromEeprom;
        for (index = 0; index < 16; index++) {
            return_status |= nvmem_read(NVMEM_RM_FILEID, 8, 8*index, pRMParams);
            pRMParams += 8;
        }
        counter++;
    }

    // If RM file is not valid, load the default one.
    if (counter == 3) {
        printf("RM is not valid, loading default one...\n");
        pRMParams = (unsigned char *)cRMdefaultParams;
    } else {
        printf("RM is valid.\n");
        pRMParams = cRMParamsFromEeprom;
    }

    return_status = 1;

    printf("Writing new FAT\n");
    while (return_status) {
        // Write new FAT.
        return_status = fat_write_content(aFATEntries[0], aFATEntries[1]);
    }

    return_status = 1;

    printf("Writing RM parameters...\n");
    while (return_status) {
        // Write RM parameters.
        // Write in 4 parts to work with tiny driver.
        return_status = 0;

        for (index = 0; index < 4; index++) {
            return_status |= nvmem_write(NVMEM_RM_FILEID,
                                         32,
                                         32*index,
                                         (pRMParams + 32*index)); 
        }
    }

    return_status = 1;

    // Write back the MAC address, only if exists.
    if (mac_status == 0) {
        // Zero out MCAST bit if set.
        cMacFromEeprom[0] &= 0xfe;
        printf("Writing back MAC address..\n");
        while (return_status) {
            return_status = nvmem_set_mac_address(cMacFromEeprom);
        }
    }

    // Update driver
    ucStatus_Dr = 1;
    printf("Updating driver patch...\n");
    while (ucStatus_Dr) {
        // Writing driver patch to EEPRROM - PROTABLE CODE
        // Note that the array itself is changing between the
        // different Service Packs.
        ucStatus_Dr = nvmem_write_patch(NVMEM_WLAN_DRIVER_SP_FILEID,
                                        drv_length,
                                        wlan_drv_patch);
    }

    // Update firmware
    ucStatus_FW = 1;
    printf("Updating firmware patch...\n");
    while (ucStatus_FW) {
        // Writing FW patch to EEPRROM - PROTABLE CODE
        // Note that the array itself is changing between the
        // different Service Packs.
        ucStatus_FW = nvmem_write_patch(NVMEM_WLAN_FW_SP_FILEID,
                                        fw_length,
                                        fw_patch);
    }

    printf("Update complete, resetting module\n"\
           "If this doesn't work, reset manually...\n");

    wlan_stop();
    systick_sleep(500);

    // Re-Init module and request to load with patches.
    initDriver(0);

    // If MAC does not exist, it is recommended
    // that the user will write a valid mac address.
    if (mac_status != 0) {
        printf("MAC address is not valid, please write a new one\n");
    }

    // Patch update done
    printf("All done, call wlan.patch_version()\n");
}
Ejemplo n.º 13
0
bool wlan_reset_credentials_store_required()
{
	wlan_start(0);	// needed for nvmem_read
	bool has_nvmem = nvmem_read(NVMEM_SPARK_FILE_ID, NVMEM_SPARK_FILE_SIZE, 0, NVMEM_Spark_File_Data) == NVMEM_SPARK_FILE_SIZE;
    return (NVMEM_SPARK_Reset_SysFlag == 0x0001 || !has_nvmem);
}