예제 #1
1
파일: RSA.c 프로젝트: adelapie/irma_card
/**
 * PKCS #1 OAEP decoding
 */
static int OAEP_decode(unsigned char *message,
        unsigned int encoded_bytes, const unsigned char *encoded,
        unsigned int label_bytes, const unsigned char *label) {
  unsigned int i, message_bytes;
  unsigned char DB[RSA_MOD_BYTES - RSA_SHA_BYTES - 1 /* Add MGF1 buffer space */ + 4];
  unsigned char seed[RSA_SHA_BYTES /* Add MGF1 buffer space */ + 4];

  debugValue("OAEP decode: encoded message", encoded, encoded_bytes);

  // First byte of encoded message must be 0x00
  if(encoded[0] != 0x00) {
    debugError("First byte of OAEP encoded message is not 0x00");
    return RSA_ERROR_OAEP_DECODE;
  }

  // Extract maskedDB and maskedSeed
  debugValue("OAEP decode: maskedSeed", encoded + 1, RSA_SHA_BYTES);
  Copy(RSA_SHA_BYTES, DB, encoded + 1 + RSA_SHA_BYTES);
  debugValue("OAEP decode: maskedDB", encoded + 1 + RSA_SHA_BYTES, RSA_MOD_BYTES - RSA_SHA_BYTES - 1);

  // Finding seed and DB
  MGF1(RSA_MOD_BYTES - RSA_SHA_BYTES - 1, DB, RSA_SHA_BYTES, seed);
  debugValue("OAEP decode: seedMask", seed, RSA_SHA_BYTES);

  XorAssign(RSA_SHA_BYTES, seed, encoded + 1);
  debugValue("OAEP decode: seed", seed, RSA_SHA_BYTES);

  MGF1(RSA_SHA_BYTES, seed, RSA_MOD_BYTES - RSA_SHA_BYTES - 1, DB);
  debugValue("OAEP decode: dbMask", DB, RSA_MOD_BYTES - RSA_SHA_BYTES - 1);

  XorAssign(RSA_MOD_BYTES - RSA_SHA_BYTES - 1, DB, encoded + 1 + RSA_SHA_BYTES);
  debugValue("OAEP decode: DB", DB, RSA_MOD_BYTES - RSA_SHA_BYTES - 1);

  // Compute the hash of l
  debugValue("OAEP decode: label", label, label_bytes);
  SHA(RSA_SHA_BYTES, seed, label_bytes, label);
  debugValue("OAEP decode: hash of label", seed, RSA_SHA_BYTES);

  // Check whether the first RSA_SHA_BYTES bytes of DB equal to lHash
  if (NotEqual(RSA_SHA_BYTES, seed, DB)) {
    debugError("First RSA_SHA_BYTES of DB do not match with hash of label");
    return RSA_ERROR_OAEP_DECODE;
  }

  // Try to locate the message in DB
  i = RSA_SHA_BYTES;
  while ((DB[i] == 0x00) && (DB[i] != 0x01) && (i < (RSA_MOD_BYTES - RSA_SHA_BYTES - 1 - 1))) i++;

  if ((i == (RSA_MOD_BYTES - RSA_SHA_BYTES - 1 - 1)) || (DB[i] != 0x01)) {
    debugError("Failed to locate the message in DB");
    return RSA_ERROR_OAEP_DECODE;
  }

  // Extract the message, starting after 0x01 byte to the end of DB
  message_bytes = RSA_MOD_BYTES - RSA_SHA_BYTES - 1 - 1 - (i + 1) + 1;
  CopyBytes(message_bytes, message, DB + i + 1);
  debugValue("OAEP decode: recovered message", message, message_bytes);

  return message_bytes;
}
예제 #2
0
// ----------------------------------------------------
// Function called when we want to start the server.
// This function expects the following parameter to be passed:
// the directory of the server we want to start and the
// command line (and its argumets) that we want to execute (basically the java
// command that we want to start the server).  The main reasons
// to have the command line passed are:
// 1. Keep the native code as minimal as possible.
// 2. Allow the administrator some flexibility in the way the
// server is started by leaving most of the logic in the command-line.
//
// This approach makes things to be closer between what is proposed
// in windows and in UNIX systems.
//
// If the instance could be started the code will write the pid of the process
// of the server in file that can be used for instance to stop the server
// (see stop.c).
//
// Returns the pid of the process of the instance if it could be started and -1
// otherwise.
// ----------------------------------------------------
int start(const char* instanceDir, char* argv[])
{
  int returnValue;
  int childPid;

  char command[COMMAND_SIZE];

  if (getCommandLine(argv, command, COMMAND_SIZE))
  {
    childPid = spawn(command, TRUE);

    if (childPid > 0)
    {
      createPidFile(instanceDir, childPid);
      returnValue = childPid;
    }
    else
    {
      debugError("Couldn't start the child process because the spawn failed.");
      returnValue = -1;
    }
  }
  else
  {
    debugError("Couldn't start the child process because the full command line could not be constructed.");
    returnValue = -1;
  }

  return returnValue;
} // start
예제 #3
0
// ----------------------------------------------------
// Creates the pid file for a given instance directory.
// and a given pid.
// If the file could be created returns TRUE and FALSE
// otherwise.
// ----------------------------------------------------
BOOL createPidFile(const char* instanceDir, int pid)
{
  BOOL returnValue = FALSE;
  char pidFile[PATH_SIZE];
  FILE *f;

  debug("createPidFile(instanceDir='%s',pid=%d)", instanceDir, pid);

  if (getPidFile(instanceDir, pidFile, PATH_SIZE))
  {
    if ((f = fopen(pidFile, "w")) != NULL)
    {
      fprintf(f, "%d", pid);
      fclose (f);
      returnValue = TRUE;
      debug("Successfully put pid=%d in the pid file '%s'.", pid, pidFile);
    }
    else
    {
      debugError("Couldn't create the pid file '%s' because the file could not be opened.", pidFile);
      returnValue = FALSE;
    }
  }
  else
  {
    debugError("Couldn't create the pid file because the pid file name could not be constructed.");
    returnValue = FALSE;
  }

  return returnValue;
}  // createPidFile
예제 #4
0
// The goal of these methods is:
// Be able to launch batch files with double-click and not having a
// prompt-window associated with it.
// Launch batch files from the prompt that generate a java process that does not
// block the prompt and that keeps running even if the prompt window is closed.
//
// This function expects the following parameter to be passed:
// the directory of the server we want to start and the
// command line that we want to execute (basically the java
// command that we want to display the status panel).  The main reasons
// to have the command line passed are:
// 1. Keep the native code as minimal as possible.
// 2. Allow the administrator some flexibility in the way the
// server is started by leaving most of the logic in the command-line.
//
// Returns the pid of the process associated with the command if it could be
// launched and -1 otherwise.
// ----------------------------------------------------
int launch(char* argv[])
{
  int returnValue;

  char command[COMMAND_SIZE];

  if (getCommandLine(argv, command, COMMAND_SIZE))
  {
    returnValue = spawn(command, TRUE);
    if (returnValue <= 0)
    {
      debugError("Failed to launch the child process '%s'.", command);
    }
    else
    {
      debug("Successfully launched the child process '%s'.", command);
    }
  }
  else
  {
    debugError("Couldn't launch the child process because the full command line could not be constructed.");
    returnValue = -1;
  }

  return returnValue;
} // launch
예제 #5
0
bool
VolumeControlLowRes::setValue(int v)
{
    uint32_t reg;
    uint32_t old_reg;
    
    if (v>0xFF) v=0xFF;
    else if (v<0) v=0;

    if ( !m_Parent.getSpecificValue(m_cmd_id, &reg) ) {
        debugError( "getSpecificValue failed\n" );
        return 0;
    }
    
    old_reg=reg;
    reg &= ~(0xFF<<m_bit_shift);
    reg |= (v<<m_bit_shift);

    debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d, shift %d (reg: 0x%08X => 0x%08X)\n", 
                                     m_cmd_id, v, m_bit_shift, old_reg, reg);

    if ( !m_Parent.setSpecificValue(m_cmd_id, reg) ) {
        debugError( "setSpecificValue failed\n" );
        return false;
    } else return true;
}
예제 #6
0
bool
EfcCmd::deserialize( Util::Cmd::IISDeserialize& de )
{
    bool result=true;
    
    result &= de.read(&m_length);
    m_length=CondSwapFromBus32(m_length);
    
    // read the EFC header
    quadlet_t *header_as_quadlets=(quadlet_t *)&m_header;
    for (unsigned int i=0; i<sizeof(m_header)/4; i++) {
        result &= de.read((header_as_quadlets+i));
        *(header_as_quadlets+i)=CondSwapFromBus32(*(header_as_quadlets+i));
    }

    // check the EFC version
    if(m_header.version > 1) {
        debugError("Unsupported EFC version: %d\n", m_header.version);
        return false;
    }

    // check whether the category and command of the response are valid
    if (m_header.category != m_category_id) {
        debugError("Invalid category response: %d != %d\n", m_header.category, m_category_id);
        return false;
    }
    if (m_header.command != m_command_id) {
        debugError("Invalid command response: %d != %d\n", m_header.command, m_command_id);
        return false;
    }
    return result;
}
예제 #7
0
bool SaffirePro24::discover() {
    if (Dice::Device::discover()) {
        fb_quadlet_t* version = (fb_quadlet_t *)calloc(2, sizeof(fb_quadlet_t));
        getEAP()->readRegBlock(Dice::EAP::eRT_Application, SAFFIRE_PRO24_REGISTER_APP_VERSION, version, 1*sizeof(fb_quadlet_t));
        // On August 2013, Focusrite released a new firmware.
        // Version numbering 2.0 (0x00020000) seems common to all Saffire 
        // Dice EAP devices.
        // Note: 0x00010004 and 0x00010008 stands for a firmware version 
        // not for a device identity.  0x00010004 is a pro24, 0x00010008 
        // is the pro24dsp.
        if (version[0] != 0x00010004 && version[0] != 0x00010008 && version[0] != 0x00020000) {
            debugError("This is a Focusrite Saffire Pro24 but not the right firmware. Better stop here before something goes wrong.\n");
            debugError("This device has firmware 0x%x while we only know about versions 0x%x, 0x%x and 0x%x.\n", version[0], 0x10004, 0x10008, 0x00020000);
            return false;
        }

        // FIXME: What is the purpose of the following commented lines at this point ?
        //getEAP()->readRegBlock(Dice::EAP::eRT_Command, 0x00, tmp, 2*sizeof(fb_quadlet_t)); // DEBUG
        //hexDumpQuadlets(tmp, 2); // DEBUG

        FocusriteEAP* eap = dynamic_cast<FocusriteEAP*>(getEAP());
        SaffirePro24EAP::MonitorSection* monitor = new SaffirePro24EAP::MonitorSection(eap, "Monitoring");
        getEAP()->addElement(monitor);
        return true;
    }
    return false;
}
예제 #8
0
uint8_t
Device::getConfigurationIdNumberOfChannel( PlugAddress::EPlugDirection ePlugDirection )
{
    ExtendedPlugInfoCmd extPlugInfoCmd( get1394Service() );
    UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR,
                                     0 );
    extPlugInfoCmd.setPlugAddress( PlugAddress( ePlugDirection,
                                                PlugAddress::ePAM_Unit,
                                                unitPlugAddress ) );
    extPlugInfoCmd.setNodeId( getNodeId() );
    extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
    extPlugInfoCmd.setVerbose( getDebugLevel() );
    ExtendedPlugInfoInfoType extendedPlugInfoInfoType(
        ExtendedPlugInfoInfoType::eIT_NoOfChannels );
    extendedPlugInfoInfoType.initialize();
    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );

    if ( !extPlugInfoCmd.fire() ) {
        debugError( "Number of channels command failed\n" );
        return 0;
    }

    ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
    if ( infoType
         && infoType->m_plugNrOfChns )
    {
        debugOutput(DEBUG_LEVEL_VERBOSE, "Number of channels 0x%02x\n",
                    infoType->m_plugNrOfChns->m_nrOfChannels );
        return infoType->m_plugNrOfChns->m_nrOfChannels;
    }

    debugError( "Could not retrieve number of channels\n" );
    return 0;
}
예제 #9
0
bool
BinaryControl::setValue(int v)
{
    uint32_t reg;
    uint32_t old_reg;

    if ( !m_Parent.getSpecificValue(m_cmd_id, &reg) ) {
        debugError( "getSpecificValue failed\n" );
        return 0;
    }
    
    old_reg=reg;
    if (v) {
        reg |= (1<<m_cmd_bit);
    } else {
        reg &= ~(1<<m_cmd_bit);
    }
    debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d (reg: 0x%08X => 0x%08X)\n", 
                                     m_cmd_id, v, old_reg, reg);

    if ( !m_Parent.setSpecificValue(m_cmd_id, reg) ) {
        debugError( "setSpecificValue failed\n" );
        return false;
    } else return true;
}
예제 #10
0
uint8_t
Device::getConfigurationIdSampleRate()
{
    ExtendedStreamFormatCmd extStreamFormatCmd( get1394Service() );
    UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 );
    extStreamFormatCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
                                                    PlugAddress::ePAM_Unit,
                                                    unitPlugAddress ) );

    extStreamFormatCmd.setNodeId( getNodeId() );
    extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status );
    extStreamFormatCmd.setVerbose( getDebugLevel() );

    if ( !extStreamFormatCmd.fire() ) {
        debugError( "Stream format command failed\n" );
        return 0;
    }

    FormatInformation* formatInfo =
        extStreamFormatCmd.getFormatInformation();
    FormatInformationStreamsCompound* compoundStream
        = dynamic_cast< FormatInformationStreamsCompound* > (
            formatInfo->m_streams );
    if ( compoundStream ) {
        debugOutput(DEBUG_LEVEL_VERBOSE, "Sample rate 0x%02x\n",
                    compoundStream->m_samplingFrequency );
        return compoundStream->m_samplingFrequency;
    }

    debugError( "Could not retrieve sample rate\n" );
    return 0;
}
예제 #11
0
bool
Device::destroyMixer() {
    bool ret = true;
    debugOutput(DEBUG_LEVEL_VERBOSE, "destroy mixer...\n");

    if (m_MixerContainer == NULL) {
        debugOutput(DEBUG_LEVEL_VERBOSE, "no mixer to destroy...\n");
    } else
    if (!deleteElement(m_MixerContainer)) {
        debugError("Mixer present but not registered to the avdevice\n");
        ret = false;
    } else {
        // remove and delete (as in free) child control elements
        m_MixerContainer->clearElements(true);
        delete m_MixerContainer;
        m_MixerContainer = NULL;
    }

    // remove control container
    if (m_ControlContainer == NULL) {
        debugOutput(DEBUG_LEVEL_VERBOSE, "no controls to destroy...\n");
    } else
    if (!deleteElement(m_ControlContainer)) {
        debugError("Controls present but not registered to the avdevice\n");
        ret = false;
    } else {
        // remove and delete (as in free) child control elements
        m_ControlContainer->clearElements(true);
        delete m_ControlContainer;
        m_ControlContainer = NULL;
    }

    return false;
}
예제 #12
0
// this has to wait until the ISO channel numbers are written
bool
SlaveDevice::startStreamByIndex(int i) {

    if (i<(int)m_receiveProcessors.size()) {
        int n=i;
        Streaming::StreamProcessor *p=m_receiveProcessors.at(n);

        // the other side sends on this channel
        nodeaddr_t iso_channel_offset = BOUNCE_REGISTER_RX_ISOCHANNEL;
        iso_channel_offset += ((unsigned)n)*4;

        if (!waitForRegisterNotEqualTo(iso_channel_offset, 0xFFFFFFFFLU)) {
            debugError("Timeout waiting for stream %d to get an ISO channel\n",i);
            return false;
        }

        fb_quadlet_t result;
        // this will read from our own registers
        if (!readReg(iso_channel_offset, &result)) {
            debugError("Could not read ISO channel register for stream %d\n",i);
            return false;
        }

        // set ISO channel
        p->setChannel(result);

        return true;

    } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) {
        int n=i-m_receiveProcessors.size();
        Streaming::StreamProcessor *p = m_transmitProcessors.at(n);

        // the other side sends on this channel
        nodeaddr_t iso_channel_offset = BOUNCE_REGISTER_TX_ISOCHANNEL;
        iso_channel_offset += ((unsigned)n)*4;

        if (!waitForRegisterNotEqualTo(iso_channel_offset, 0xFFFFFFFF)) {
            debugError("Timeout waiting for stream %d to get an ISO channel\n",i);
            return false;
        }

        fb_quadlet_t result;
        // this will read from our own registers
        if (!readReg(iso_channel_offset, &result)) {
            debugError("Could not read ISO channel register for stream %d\n",i);
            return false;
        }

        // set ISO channel
        p->setChannel(result);

        return true;

    }

    debugError("SP index %d out of range!\n",i);

    return false;
}
예제 #13
0
void
PosixMutex::Lock()
{
    int err;
    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) lock\n", m_id.c_str(), this);
    #if DEBUG_LOCK_COLLISION_TRACING
    if(TryLock()) {
        // locking succeeded
        m_locked_by = debugBacktraceGet( DEBUG_LOCK_COLLISION_TRACING_INDEX );

        char name[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ];
        name[0] = 0;
        debugGetFunctionNameFromAddr(m_locked_by, name, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN);

        debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,
                    "(%s, %p) %s obtained lock\n",
                    m_id.c_str(), this, name);
        return;
    } else {
        void *lock_try_by = debugBacktraceGet( DEBUG_LOCK_COLLISION_TRACING_INDEX );

        char name1[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ];
        name1[0] = 0;
        debugGetFunctionNameFromAddr(lock_try_by, name1, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN);
        char name2[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ];
        name2[0] = 0;
        debugGetFunctionNameFromAddr(m_locked_by, name2, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN);

        debugWarning("(%s, %p) lock collision: %s wants lock, %s has lock\n",
                    m_id.c_str(), this, name1, name2);
        if((err = pthread_mutex_lock(&m_mutex))) {
            if (err == EDEADLK) {
                debugError("(%s, %p) Resource deadlock detected\n", m_id.c_str(), this);
                debugPrintBacktrace(10);
            } else {
                debugError("(%s, %p) Error locking the mutex: %d\n", m_id.c_str(), this, err);
            }
        } else {
            debugWarning("(%s, %p) lock collision: %s got lock (from %s?)\n",
                        m_id.c_str(), this, name1, name2);
        }
    }
    #else
    #ifdef DEBUG
    if((err = pthread_mutex_lock(&m_mutex))) {
        if (err == EDEADLK) {
            debugError("(%s, %p) Resource deadlock detected\n", m_id.c_str(), this);
            debugPrintBacktrace(10);
        } else {
            debugError("(%s, %p) Error locking the mutex: %d\n", m_id.c_str(), this, err);
        }
    }
    #else
    pthread_mutex_lock(&m_mutex);
    #endif
    #endif
}
예제 #14
0
// ----------------------------------------------------
// main function called by the executable.  This code is
// called by the start-ds.bat, stop-ds.bat and statuspanel.bat batch files.
//
// The code assumes that the first passed argument is the subcommand to be
// executed and for start and stop the second argument the directory of the
// server.
// The rest of the arguments are the arguments specific to each subcommand (see
// the comments for the functions start, stop and launch).
// ----------------------------------------------------
int main(int argc, char* argv[])
{
  int returnCode;
  char* subcommand = NULL;
  char* instanceDir = NULL;
  int i;

  debug("main called.");
  for (i = 0; i < argc; i++) {
    debug("  argv[%d] = '%s'", i, argv[i]);
  }

  if (argc < 3) {
    char * msg =
      "Expected command line args of [subcommand], but got %d arguments.\n";
    debugError(msg, argc - 1);
    fprintf(stderr, msg, argc - 1);
	  return -1;
  }

  subcommand = argv[1];

  if (strcmp(subcommand, "start") == 0)
  {
    instanceDir = argv[2];
    argv += 3;
    returnCode = start(instanceDir, argv);
  }
  else if (strcmp(subcommand, "stop") == 0)
  {
    instanceDir = argv[2];
    argv += 3;
    returnCode = stop(instanceDir);
  }
  else if (strcmp(subcommand, "launch") == 0)
  {
    argv += 2;
    returnCode = launch(argv);
  }
  else if (strcmp(subcommand, "run") == 0)
  {
    argv += 2;
    returnCode = run(argv);
  }
  else
  {
    char * msg = "Unknown subcommand: [%s]\n";
    debugError(msg, subcommand);
    fprintf(stderr, msg, subcommand);
    returnCode = -1;
  }
  debug("main finished. Returning %d", returnCode);
  return returnCode;
}
예제 #15
0
/*---------------------------------------------------------------------------
 * Handles the interface reset in the case of an idle.
 ---------------------------------------------------------------------------*/
int EInterfaces::reset_if_idle(UInt64 TimeOut)
{
	int n;
	int nRet = 0;
	
	for(n=0; n<numberof(m_aInterfaces); n++)
		if ( m_aInterfaces[n].m_fEnabled && (m_aInterfaces[n].m_TimeSinceLastSend!=0) )
		{
			debug("Interface[%d] - time since idle=%luus\n", n,  time_since_now_us(m_aInterfaces[n].m_TimeSinceLastSend));

			// Check if our interface has actually timed out
			if ( time_since_now_us(m_aInterfaces[n].m_TimeSinceLastSend) > TimeOut )
			{
				debug("RESETTING IDLE LINK on interface %d\n", n);

				// Reset values
				set_cwnd(m_aInterfaces[n].m_ifnet, 1);
				set_ssthresh(m_aInterfaces[n].m_ifnet, m_aInterfaces[n].get_max_outstanding_all_shelves()/2);
				
				// Since the link is idle, we would expect the number of outstanding commands to be zero. If it isn't
				// something has gone wrong and we reset it to prevent commands not being sent again
				if ( 0!=m_aInterfaces[n].m_nOutstandingCount )
				{
					debugError("Outstanding count is not zero, but the interface is idle. Resetting to prevent deadlock\n");
					m_aInterfaces[n].m_nOutstandingCount = 0;
				}
			}
		}

	
	return nRet;
}
예제 #16
0
파일: Watchdog.cpp 프로젝트: EMATech/ffado
bool
Watchdog::WatchdogHartbeatTask::Execute()
{
    if (Watchdog::WatchdogTask::Execute() == false)
        return false;

    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,
                "(%p) watchdog %p hartbeat\n", this, &m_parent);
    m_parent.setHartbeat();

    #ifdef DEBUG
    uint64_t now = Util::SystemTimeSource::getCurrentTimeAsUsecs();
    int diff = now - m_last_loop_entry;
    if(diff < 100) {
        debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE,
                           "(%p) short loop detected (%d usec), cnt: %d\n",
                           this, diff, m_successive_short_loops);
        m_successive_short_loops++;
        if(m_successive_short_loops > 100) {
            debugError("Shutting down runaway thread\n");
            return false;
        }
    } else {
        // reset the counter
        m_successive_short_loops = 0;
    }
    m_last_loop_entry = now;
    #endif

    return true;
}
예제 #17
0
bool ModulatorSamplerSoundPool::loadMonolithicData(const ValueTree &sampleMap, const Array<File>& monolithicFiles, OwnedArray<ModulatorSamplerSound> &sounds)
{
	jassert(!mc->getMainSynthChain()->areVoicesActive());

	clearUnreferencedMonoliths();

	loadedMonoliths.add(new MonolithInfoToUse(monolithicFiles));

	MonolithInfoToUse* hmaf = loadedMonoliths.getLast();

	try
	{
		hmaf->fillMetadataInfo(sampleMap);
	}
	catch (StreamingSamplerSound::LoadingError l)
	{
		String x;
		x << "Error at loading sample " << l.fileName << ": " << l.errorDescription;
		mc->getDebugLogger().logMessage(x);

#if USE_FRONTEND
		mc->sendOverlayMessage(DeactiveOverlay::State::CustomErrorMessage, x);
#else
		debugError(mc->getMainSynthChain(), x);
#endif
	}

	for (int i = 0; i < sampleMap.getNumChildren(); i++)
	{
		ValueTree sample = sampleMap.getChild(i);

		if (sample.getNumChildren() == 0)
		{
			String fileName = sample.getProperty("FileName").toString().fromFirstOccurrenceOf("{PROJECT_FOLDER}", false, false);
			StreamingSamplerSound* sound = new StreamingSamplerSound(hmaf, 0, i);
			pool.add(sound);
			sounds.add(new ModulatorSamplerSound(mc, sound, i));
		}
		else
		{
			StreamingSamplerSoundArray multiMicArray;

			for (int j = 0; j < sample.getNumChildren(); j++)
			{
				StreamingSamplerSound* sound = new StreamingSamplerSound(hmaf, j, i);
				pool.add(sound);
				multiMicArray.add(sound);
			}

			sounds.add(new ModulatorSamplerSound(mc, multiMicArray, i));
		}

		
	}


	sendChangeMessage();

	return true;
}
예제 #18
0
int AoEProperties::configure_matching(void)
{
//	debugVerbose("AoEProperties::configure_matching\n");
	
	// Obtain ports for notifications (this will be used for all service matching notifications)
	kern_return_t kresult;
	mach_port_t MasterPort;
	kresult = IOMasterPort(MACH_PORT_NULL, &MasterPort);
	if ( kresult )
	{
		debugError("Could not get masterport. Error=%d\n", kresult);
		return false;
	}
	
	ms_NotificationPort = IONotificationPortCreate(MasterPort);
	
	ms_IOKitNotificationRunLoopSource = IONotificationPortGetRunLoopSource(ms_NotificationPort);
	CFRunLoopAddSource(CFRunLoopGetCurrent(), ms_IOKitNotificationRunLoopSource, kCFRunLoopDefaultMode);
	
	// SetUp Notification for matching to our device
	CFMutableDictionaryRef MatchingDict = IOServiceMatching(AOE_KEXT_NAME_Q);

	IOServiceAddMatchingNotification(ms_NotificationPort,
									 kIOMatchedNotification,
									 MatchingDict,
									 AoEProperties::matched_callback,
									 this,
									 &ms_MatchIt);
	
	// Call the callback immediately to check if our iterator already contains our device (ie. the device is already loaded)
	matched_callback(this, ms_MatchIt);
	
	return m_fMatched ? 0 : -1;
}
예제 #19
0
void* thread_function(void* arg)
{
    struct thread_args* obj = (struct thread_args*)arg;
    int err;

    if ((err = pthread_setcanceltype(obj->fCancellation, NULL)) != 0) {
        debugError("pthread_setcanceltype err = %s\n", strerror(err));
    }

    debugOutput( DEBUG_LEVEL_VERBOSE, "start %p\n", obj);
    uint64_t now = getCurrentTimeAsUsecs();
    uint64_t wake_at = now += SLEEP_PERIOD_USECS;
    // If Init succeed start the thread loop
    while (obj->fRunning) {
        debugOutput( DEBUG_LEVEL_VERBOSE, "run %p\n", obj);
        
        SleepUsecAbsolute(wake_at);
        wake_at += SLEEP_PERIOD_USECS;
        
        debugOutput(DEBUG_LEVEL_VERBOSE,
                    "cuckoo from %p at %012" PRI_FFADO_MICROSECS_T "\n",
                    obj, getCurrentTimeAsUsecs());
        
        pthread_testcancel();
    }

    debugOutput( DEBUG_LEVEL_VERBOSE, "exit %p\n", obj);
    return 0;
}
예제 #20
0
void EInterfaces::recalculate_mtu(void)
{
	UInt32	Min_MTU;
	int		n;

	Min_MTU = 0;
	
	for(n=0; n<numberof(m_aInterfaces); n++)
	{
		if ( m_aInterfaces[n].m_fEnabled )
		{
			if ( Min_MTU )
				Min_MTU = MIN(ifnet_mtu(m_aInterfaces[n].m_ifnet), Min_MTU);
			else
				Min_MTU = ifnet_mtu(m_aInterfaces[n].m_ifnet);
		}
	}
	
	if ( 0==Min_MTU )
	{
		debugError("Error in MTU calculation.\n");
		m_Min_MTU = 1500;		// Set to standard MTU size
	}
	
	m_Min_MTU = Min_MTU;
	
	debug("Minimum MTU of %d interface(s) is %d bytes\n", m_nInterfacesInUse, m_Min_MTU);
}
예제 #21
0
FFADODevice::FFADODevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) )
    : Control::Container()
    , m_pConfigRom( configRom )
    , m_pDeviceManager( d )
{
    addOption(Util::OptionContainer::Option("id",std::string("dev?")));

    std::ostringstream nodestr;
    nodestr << "node" << getConfigRom().getNodeId();

    if (!addElement(&getConfigRom())) {
        debugWarning("failed to add ConfigRom to Control::Container\n");
    }

    m_genericContainer = new Control::Container("Generic");
    if(m_genericContainer == NULL) {
        debugError("Could not create Control::Container for generic controls\n");
    } else {

        if (!addElement(m_genericContainer)) {
            debugWarning("failed to add generic container to Control::Container\n");
        }
        // add a generic control for the clock source selection
        if(!m_genericContainer->addElement(new Control::ClockSelect(*this))) {
            debugWarning("failed to add clock source control to container\n");
        }
    }
}
예제 #22
0
bool
Device::setActiveClockSource(ClockSource s)
{
	AVC::SignalSourceCmd cmd(get1394Service());
    cmd.setCommandType(AVC::AVCCommand::eCT_Control);
    cmd.setNodeId(getNodeId());
    cmd.setSubunitType(AVC::eST_Unit);
    cmd.setSubunitId(0xff);
    cmd.setVerbose(getDebugLevel());

    AVC::SignalSubunitAddress dst;
    dst.m_subunitType = AVC::eST_Music;
    dst.m_subunitId = 0x00;
    dst.m_plugId = 0x05;
    cmd.setSignalDestination(dst);

    if (s.id == 0x00) {
        AVC::SignalSubunitAddress src;
        src.m_subunitType = AVC::eST_Music;
        src.m_subunitId = 0x00;
        src.m_plugId = 0x06;
        cmd.setSignalSource( src );
    } else {
        AVC::SignalUnitAddress src;
        src.m_plugId = 0x83;
        cmd.setSignalSource(src);
    }

    if (!cmd.fire()) {
        debugError( "Signal source command failed\n" );
        return false;
    }

    return true;
}
예제 #23
0
int
main() {
    setDebugLevel(DEBUG_LEVEL_VERBOSE);

    struct thread_args args[NB_THREADS];
    pthread_t threads[NB_THREADS];

    int res=0;

    for (int i=0; i<NB_THREADS; i++) {
        args[i].fRunning = true;
        args[i].fCancellation = PTHREAD_CANCEL_DEFERRED;
        if ((res = pthread_create(&threads[i], 0, thread_function, &args[i]))) {
            debugError("Cannot set create thread %d %s\n", res, strerror(res));
            return -1;
        }
        debugOutput( DEBUG_LEVEL_VERBOSE, "created thread: %p\n", &args[i]);
    }


    SleepUsecRelative(RUNTIME_USECS);
    
    for (int i=0; i<NB_THREADS; i++) {
        debugOutput( DEBUG_LEVEL_VERBOSE, "Stop thread: %p\n", &args[i]);
        void* status;
        args[i].fRunning = false; // Request for the thread to stop
        pthread_join(threads[i], &status);
        debugOutput( DEBUG_LEVEL_VERBOSE, "Stopped thread: %p\n", &args[i]);
    }

}
예제 #24
0
int
Device::getSelectorFBValue(int id) {

    FunctionBlockCmd fbCmd( get1394Service(),
                            FunctionBlockCmd::eFBT_Selector,
                            id,
                            FunctionBlockCmd::eCA_Current );
    fbCmd.setNodeId( getNodeId() );
    fbCmd.setSubunitId( 0x00 );
    fbCmd.setCommandType( AVCCommand::eCT_Status );
    fbCmd.m_pFBSelector->m_inputFbPlugNumber = 0xFF;
    fbCmd.setVerboseLevel( getDebugLevel() );

    if ( !fbCmd.fire() ) {
        debugError( "cmd failed\n" );
        return -1;
    }
    
//     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
//         Util::Cmd::CoutSerializer se;
//         fbCmd.serialize( se );
//     }

    if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) {
        debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n");
    }
    
    return fbCmd.m_pFBSelector->m_inputFbPlugNumber;
}
예제 #25
0
void
PosixMutex::Unlock()
{
    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) unlock\n", m_id.c_str(), this);
    #if DEBUG_LOCK_COLLISION_TRACING
    // unlocking
    m_locked_by = NULL;
    void *unlocker = debugBacktraceGet( DEBUG_LOCK_COLLISION_TRACING_INDEX );
    char name[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ];
    name[0] = 0;
    debugGetFunctionNameFromAddr(unlocker, name, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN);
    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,
                "(%s, %p)  %s releases lock\n",
                m_id.c_str(), this, name);
    #endif

    #ifdef DEBUG
    int err;
    if((err = pthread_mutex_unlock(&m_mutex))) {
        debugError("(%s, %p) Error unlocking the mutex: %d\n", m_id.c_str(), this, err);
    }
    #else
    pthread_mutex_unlock(&m_mutex);
    #endif
}
예제 #26
0
bool
Device::setFeatureFBLRBalanceCurrent(int id, int channel, int v) {

    FunctionBlockCmd fbCmd( get1394Service(),
                            FunctionBlockCmd::eFBT_Feature,
                            id,
                            FunctionBlockCmd::eCA_Current );
    fbCmd.setNodeId( getNodeId() );
    fbCmd.setSubunitId( 0x00 );
    fbCmd.setCommandType( AVCCommand::eCT_Control );
    fbCmd.m_pFBFeature->m_audioChannelNumber = channel;
    fbCmd.m_pFBFeature->m_controlSelector = FunctionBlockFeature::eCSE_Feature_LRBalance;
    AVC::FunctionBlockFeatureLRBalance bl;
    fbCmd.m_pFBFeature->m_pLRBalance = bl.clone();
    fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance = v;
    fbCmd.setVerboseLevel( getDebugLevel() );

    if ( !fbCmd.fire() ) {
        debugError( "cmd failed\n" );
        return false;
    }

//     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
//         Util::Cmd::CoutSerializer se;
//         fbCmd.serialize( se );
//     }
    
    if((fbCmd.getResponse() != AVCCommand::eR_Accepted)) {
        debugWarning("fbCmd.getResponse() != AVCCommand::eR_Accepted\n");
    }

    return (fbCmd.getResponse() == AVCCommand::eR_Accepted);
}
예제 #27
0
bool AmdtpTransmitStreamProcessor::prepareChild()
{
    debugOutput ( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this );
    m_syt_interval = getSytInterval();
    m_fdf = getFDF();

    debugOutput ( DEBUG_LEVEL_VERBOSE, " SYT interval / FDF             : %d / %d\n", m_syt_interval, m_fdf );
#if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT
    debugOutput ( DEBUG_LEVEL_VERBOSE, " Send payload in No-Data packets: %s \n", m_send_nodata_payload?"Yes":"No" );
#endif
    debugOutput ( DEBUG_LEVEL_VERBOSE, " Max early transmit cycles      : %d\n", m_max_cycles_to_transmit_early );
    debugOutput ( DEBUG_LEVEL_VERBOSE, " Transfer delay                 : %d\n", m_transmit_transfer_delay );
    debugOutput ( DEBUG_LEVEL_VERBOSE, " Min cycles before presentation : %d\n", m_min_cycles_before_presentation );

    iec61883_cip_init (
        &m_cip_status,
        IEC61883_FMT_AMDTP,
        m_fdf,
        m_StreamProcessorManager.getNominalRate(),
        m_dimension,
        m_syt_interval );

    if (!initPortCache()) {
        debugError("Could not init port cache\n");
        return false;
    }

    return true;
}
예제 #28
0
int
Device::getFeatureFBLRBalanceValue(int id, int channel, FunctionBlockCmd::EControlAttribute controlAttribute) 
{
    FunctionBlockCmd fbCmd( get1394Service(),
                            FunctionBlockCmd::eFBT_Feature,
                            id,
                            controlAttribute);
    fbCmd.setNodeId( getNodeId() );
    fbCmd.setSubunitId( 0x00 );
    fbCmd.setCommandType( AVCCommand::eCT_Status );
    fbCmd.m_pFBFeature->m_audioChannelNumber = channel;
    fbCmd.m_pFBFeature->m_controlSelector = FunctionBlockFeature::eCSE_Feature_LRBalance;
    AVC::FunctionBlockFeatureLRBalance bl;
    fbCmd.m_pFBFeature->m_pLRBalance = bl.clone();
    fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance = 0;
    fbCmd.setVerboseLevel( getDebugLevel() );

    if ( !fbCmd.fire() ) {
        debugError( "cmd failed\n" );
        return 0;
    }
    
//     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
//         Util::Cmd::CoutSerializer se;
//         fbCmd.serialize( se );
//     }

    if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) {
        debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n");
    }
    
    int16_t balance=(int16_t)(fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance);

    return balance;
}
예제 #29
0
// helpers
bool
SlaveDevice::waitForRegisterNotEqualTo(nodeaddr_t offset, fb_quadlet_t v) {
    debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for StreamProcessor streams to start running...\n");
    // we have to wait until all streamprocessors indicate that they are running
    // i.e. that there is actually some data stream flowing
    int timeoutSecs=120;
    if(!getOption("isoTimeoutSecs", timeoutSecs)) {
        debugWarning("Could not retrieve isoTimeoutSecs parameter, defauling to 120secs\n");
    }

    int wait_cycles=timeoutSecs*10; // two seconds

    fb_quadlet_t reg=v;

    while ((v == reg) && wait_cycles) {
        wait_cycles--;
        if (!readReg(offset,&reg)) {
            debugError("Could not read register\n");
            return false;
        }
        SleepRelativeUsec(100000);
    }

    if(!wait_cycles) { // timout has occurred
        return false;
    }

    return true;
}
예제 #30
0
int
Device::getProcessingFBMixerSingleCurrent(int id, int iPlugNum,
                                    int iAChNum, int oAChNum)
{
	AVC::FunctionBlockCmd fbCmd(get1394Service(),
                           AVC::FunctionBlockCmd::eFBT_Processing,
                           id,
                           AVC::FunctionBlockCmd::eCA_Current);
    fbCmd.setNodeId(getNodeId());
    fbCmd.setSubunitId(0x00);
    fbCmd.setCommandType(AVCCommand::eCT_Status);
    fbCmd.setVerboseLevel( getDebugLevel() );

    AVC::FunctionBlockProcessing *fbp = fbCmd.m_pFBProcessing;
    fbp->m_selectorLength = 0x04;
    fbp->m_fbInputPlugNumber = iPlugNum;
    fbp->m_inputAudioChannelNumber = iAChNum;
    fbp->m_outputAudioChannelNumber = oAChNum;

    // mixer object is not generated automatically
    fbp->m_pMixer = new AVC::FunctionBlockProcessingMixer;

    if ( !fbCmd.fire() ) {
        debugError( "cmd failed\n" );
        return 0;
    }

    if( (fbCmd.getResponse() != AVCCommand::eR_Implemented) ) {
        debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n");
    }

    int16_t setting = (int16_t)(fbp->m_pMixer->m_mixerSetting);

    return setting;
}