コード例 #1
0
void wbem::erasure::ErasureServiceFactory::eraseDevice(std::string password)
throw (framework::Exception)
{
	std::vector<std::string> devices = m_GetManageabledeviceUids();
	for (size_t i = 0; i < devices.size(); i++)
	{
		eraseDevice(devices[i], password);
	}
}
コード例 #2
0
/* main program starts here */
void bootloader(void)
{
#ifdef ADABOOT
  char firstcharzero=0;
#endif
  uint8_t ch,ch2;
  uint16_t w;

  error_count = 0;
  initSerial();


  /* forever loop */
  for (;;) 
    {
    bitTgl(UsbLed);

      if (error_count >= MAX_ERROR_COUNT)  // Probably normal serial traffic is causing this.
        {
          releaseChipAccess();
          return;
          //initSerial();
          //error_count = 0;
        }

      /* get character from UART */
      //bitSet(BluLed);
      ch = bootldrgetch();
      if (ch ==0)
        {
        releaseChipAccess();
        return;
        }
      //bitClr(BluLed);
      //blinkLed(GrnLedId,100*mSec,1);
      /* A bunch of if...else if... gives smaller code than switch...case ! */

#if  0 //def ADABOOT
      // Hello is anyone home ?   lady ada hack -  BBR
      if(ch=='0') {
        firstcharzero = 1; // we got an appropriate bootloader instruction
        nothing_response();
      } 
	
      else if (firstcharzero == 0) {
        // the first character we got is not '0', lets bail!
        // autoreset via watchdog (sneaky!)
        // return();
      }	
#else

      /* Hello is anyone home ? */ 
      if(ch=='0') 
        {
          nothing_response();
	}
#endif

      /* Request programmer ID */
      /* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry  */
      /* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares.  */
      else if(ch=='1') {
        if (bootldrgetch() == ' ') {
          putNch(pgmrId,9);
        } else {
          ++error_count;
        }
      }


      /* AVR ISP/STK500 board commands  DON'T CARE so default nothing_response */
      else if(ch=='@') {
        ch2 = bootldrgetch();
        if (ch2>0x85) bootldrgetch();
        nothing_response();
      }


      /* AVR ISP/STK500 board requests */
      /* Cmnd_STK_GET_PARAMETER 0x41 */
      else if(ch=='A') {
        ch2 = bootldrgetch();
        if(ch2==0x80) byte_response(HW_VER);		// Hardware version
        else if(ch2==0x81) byte_response(SW_MAJOR);	// Software major version
        else if(ch2==0x82) byte_response(SW_MINOR);	// Software minor version
        else if(ch2==0x98) byte_response(0x03);		// Unknown but seems to be required by avr studio 3.56
        else byte_response(0x00);				// Covers various unnecessary responses we don't care about
      }


      /* Cmnd_STK_SET_DEVICE 0x42
      Device Parameters  DON'T CARE, DEVICE IS FIXED  */
      else if(ch=='B') {
        getNch(20);
        nothing_response();
      }


      /* Cmnd_SET_DEVICE_EXT 0x45 */
      else if(ch=='E') {
        getNch(5);
        nothing_response();
      }

      /* P: Enter programming mode  */
      else if(ch=='P')
        {
        if (!initChipAccess(&devId[1]))
          {
          failed_response();
          }
        else nothing_response();
        }
        
      /* R: Erase device, don't care as we will erase one page at a time anyway.  */
      else if(ch=='R')
        {
        eraseDevice();
        nothing_response();
        }


      /* Leave programming mode  */
      else if(ch=='Q') 
        {
        nothing_response();
        delay(5*mSec);
        releaseChipAccess();        
        allDone();
        return;
#ifdef WATCHDOG_MODS
        assert(0);
#endif
        }


      /* Set address, little endian. EEPROM in bytes, FLASH in words  */
      /* Perhaps extra address bytes may be added in future to support > 128kB FLASH.  */
      /* This might explain why little endian was used here, big endian used everywhere else.  */
      else if(ch=='U') {
        address.word = myget2LE();
        //address.byte[0] = bootldrgetch();
        //address.byte[1] = bootldrgetch();
        nothing_response();
      }


      /* Universal SPI programming command. Used for fuses and lock bits.  */
      else if(ch=='V') {
        unsigned char spicmdbuf[4];
        bootldrgetNch(spicmdbuf,4);
                
        if (0) { // spicmdbuf[0] == 0x30) {
          if (spicmdbuf[2] == 0) {
            byte_response(SIG1);
          } else if (spicmdbuf[2] == 1) {
            byte_response(SIG2); 
          } else {
            byte_response(SIG3);
          } 
        } 
        // Call my erase device embedded routine if the erase device SPI cmd comes in
        else if ((spicmdbuf[0] == 0xac) && (spicmdbuf[1] == 0x80))
        {
        eraseDevice();
        byte_response(0);
        }
        // Don't let them program the fuse bits into a non-working clock
        // This SPI on this chip can't go slow enough to work with very slow AVR clocks (<=1mhz)
        else if ((spicmdbuf[0] == 0xAC) && (spicmdbuf[1] == 0xA0) && (((spicmdbuf[3]&0x80) == 0) || ((spicmdbuf[3]&0x0f) == 3)))
        {
              failed_response();
        }       
        else
        {
          byte_response(issueSpiCmd(spicmdbuf));
        }
      }


      /* Write memory, length is big endian and is in bytes  */
      else if(ch=='d') {
        length.word = myget2BE();
        //length.byte[1] = bootldrgetch();
        //length.byte[0] = bootldrgetch();
        flags.eeprom = 0;
        if (bootldrgetch() == 'E') flags.eeprom = 1;
        for (w=0;w<length.word;w++) 
          {
            buff[w] = bootldrgetch();	                        // Store data in buffer, can't keep up with serial data stream whilst programming pages
          }
        if (bootldrgetch() == ' ') 
          {
            if (flags.eeprom) {		                //Write to EEPROM one byte at a time
              address.word <<= 1;
              for(w=0;w<length.word;w++) {
                eeprom_write_byte((void *)address.word,buff[w]);
                address.word++;
              }			
            }
            else {					        //Write to FLASH one page at a time
              if (address.byte[1]>127) address_high = 0x01;	//Only possible with m128, m256 will need 3rd address byte. FIXME
              else address_high = 0x00;

              address.word = address.word << 1;	        //address * 2 -> byte location
              /* if ((length.byte[0] & 0x01) == 0x01) length.word++;	//Even up an odd number of bytes */
              //if ((length.byte[0] & 0x01)) length.word++;	//Even up an odd number of bytes
              if (length.word&1) length.word++; // Even up an odd number of bytes
              flash_write((void*)address.word, length.word, address_high, buff);
            }
            putNch(endStmt,2);
            //myputch(0x14);
            //myputch(0x10);
          } else {
          ++error_count;
        }		
      }


      /* Read memory block mode, length is big endian.  */
      else if(ch=='t') 
        {
        length.word = myget2BE();
        //length.byte[1] = bootldrgetch();
        //length.byte[0] = bootldrgetch();
#if defined(__AVR_ATmega128__)  || defined(__AVR_ATmega1280__)
        if (address.word>0x7FFF) flags.rampz = 1;		// No go with m256, FIXME
        else flags.rampz = 0;
#endif
        address.word = address.word << 1;	        // address * 2 -> byte location
        if (bootldrgetch() == 'E') flags.eeprom = 1;
        else flags.eeprom = 0;
        if (bootldrgetch() == ' ') 
          {		                // Command terminator
          myputch(0x14);
          if (1)
            {		        // Can handle odd and even lengths okay
            if (flags.eeprom) 
              { // Byte access EEPROM read
              for (w=0;w < length.word;w++,address.word++)
                {
                myputch(eeprom_read_byte((void *)address.word));
                }
              }
            else 
              {
              int bpos = 0;
              
              for (w=0;w < length.word;w++,address.word++,bpos++)
                {
                if (!flags.rampz) buff[bpos] = pgm_read_byte_near((void*)address.word);
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
                else buff[bpos] = pgm_read_byte_far(address.word + 0x10000);
                // Hmmmm, yuck  FIXME when m256 arrvies
#endif
                if (bpos == 63)
                  {
                  putNch(buff,64);
                  bpos = -1;
                  }
                }
              if (bpos > 0)
                {
                  putNch(buff,bpos);
                }
              }
            }
          myputch(0x10);
          }
        }


      /* Get device signature bytes  */
      else if(ch=='u') {
        if (bootldrgetch() == ' ') {
          bitSet(UsbLed);
          putNch(devId,5);
        } else {
          ++error_count;
        }
      }


      /* Read oscillator calibration byte */
      else if(ch=='v') {
        byte_response(0x00);
      }


#ifdef MONITOR
      /* here come the extended monitor commands by Erik Lins */
      /* check for three times exclamation mark pressed */
      else if(ch=='!') monitor();
#endif
      else   /* Garbled 1st character */
        {
          //printf("garbled character %d %c\n",ch,ch);
          ++error_count;
        }

    } /* end of forever loop */

}
コード例 #3
0
wbem::framework::UINT32 wbem::erasure::ErasureServiceFactory::executeMethod(
		wbem::framework::UINT32 &wbemRc,
		const std::string method,
		wbem::framework::ObjectPath &object,
		wbem::framework::attributes_t &inParms,
		wbem::framework::attributes_t &outParms)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	framework::UINT32 httpRc = framework::MOF_ERR_SUCCESS;
	wbemRc = framework::MOF_ERR_SUCCESS;

	if (method == ERASURESERVICE_ERASEDEVICE)
	{
		// uint32 EraseDevice(CIM_Job REF Job, CIM_ManagedElement REF Element,
		//						string ErasureMethod, string Password)

		// get parameters from inParms
		std::string elementObjectString = inParms[ERASURESERVICE_ERASEDEVICE_ELEMENT].stringValue();
		std::string erasureMethod = inParms[ERASURESERVICE_ERASEDEVICE_ERASUREMETHOD].stringValue();
		std::string password = inParms[ERASURESERVICE_ERASEDEVICE_PASSWORD].stringValue();

		enum eraseType eraseType = getEraseType(erasureMethod);

		if (elementObjectString.empty())
		{
			COMMON_LOG_ERROR_F("%s is required.", ERASURESERVICE_ERASEDEVICE_ELEMENT.c_str());
			httpRc = framework::CIM_ERR_INVALID_PARAMETER;
		}
		else if (erasureMethod.empty())
		{
			COMMON_LOG_ERROR_F("%s is required.", ERASURESERVICE_ERASEDEVICE_ERASUREMETHOD.c_str());
			httpRc = framework::CIM_ERR_INVALID_PARAMETER;
		}
		else if (eraseType == ERASETYPE_UNKNOWN)
		{
			COMMON_LOG_ERROR_F("Erasure Method %s is not supported", erasureMethod.c_str());
			httpRc = framework::CIM_ERR_INVALID_PARAMETER;
		}
		// Note: Password will get checked by eraseDevice
		else
		{
			// Build the object path from the attribute
			framework::ObjectPathBuilder builder(elementObjectString);
			framework::ObjectPath elementObject;
			builder.Build(&elementObject);

			try
			{
				if (elementObject.getClass() == physical_asset::NVDIMM_CREATIONCLASSNAME)
				{
					std::string deviceUidStr = elementObject.getKeyValue(TAG_KEY).stringValue();
					if (deviceUidStr.length() != NVM_MAX_UID_LEN - 1)
					{
						throw framework::ExceptionBadParameter("Tag");
					}
					NVM_UID deviceUid;
					uid_copy(deviceUidStr.c_str(), deviceUid);
					eraseDevice(deviceUidStr, password);
				}
				else if (elementObject.getClass() == software::NVDIMMCOLLECTION_CREATIONCLASSNAME)
				{
					eraseDevice(password);
				}
			}
			catch (wbem::exception::NvmExceptionLibError &e)
			{
				wbemRc = getReturnCodeFromLibException(e);
			}
			catch (wbem::framework::ExceptionBadParameter &)
			{
				httpRc = framework::CIM_ERR_INVALID_PARAMETER;
			}
		}
	}
	else if (method == ERASURESERVICE_ERASE)
	{
		// specific "Erase()" return code for "Not Supported"
		// don't use httpRc here because it's a valid method,
		// just not supported by our implementation
		wbemRc = ERASURESERVICE_ERR_NOT_SUPPORTED;
	}
	else
	{
		// all others are unsupported, including "Erase"
		httpRc = framework::CIM_ERR_METHOD_NOT_AVAILABLE;
	}

	return httpRc;
}