Exemple #1
0
void SDLoadPatch(char *fname) {
  FIL FileObject;
  FRESULT err;
  uint32_t bytes_read;

  StopPatch();

  err = f_open(&FileObject, fname, FA_READ | FA_OPEN_EXISTING);
  chThdSleepMilliseconds(10);
  if (err != FR_OK) {
    return;
  }
  err = f_read(&FileObject, (uint8_t *)PATCHMAINLOC, 0xE000,
               (void *)&bytes_read);
  if (err != FR_OK) {
    chSysHalt();
  }
  err = f_close(&FileObject);
  chThdSleepMilliseconds(10);
  StartPatch();
}
Exemple #2
0
int _tmain(int argc, _TCHAR* argv[])
{
    if (StartPatch())
    {
        printf("Error Patch\n");
        return 1;
    }

    if (RCRYPT_FAILED(CryptAcquireContext(&hProv, "test", NULL, 123, 0)))
    {
        printf("CryptAcquireConext returned error %x\n", GetLastError());
        printf("FAILED\n");
        return 1;
    }
    printf("SUCCEED\n");

    RunCert("gnivc_2006.cer");
    RunCert("rootsber.cer");
    
    return 0;
}
Exemple #3
0
void PExReceiveByte(unsigned char c) {
  static char header = 0;
  static int state = 0;
  static unsigned int index;
  static int value;
  static int position;
  static int offset;
  static int length;
  static int a;
  static int b;
  static uint32_t patchid;

  if (!header) {
    switch (state) {
    case 0:
      if (c == 'A')
        state++;
      break;
    case 1:
      if (c == 'x')
        state++;
      else
        state = 0;
      break;
    case 2:
      if (c == 'o')
        state++;
      else
        state = 0;
      break;
    case 3:
      header = c;
      if (c == 'P') { // param change
        state = 4;
      }
      else if (c == 'R') { // preset change
        state = 4;
      }
      else if (c == 'W') { // write
        state = 4;
      }
      else if (c == 'w') { // write file to SD
        state = 4;
      }
      else if (c == 'T') { // change preset
        state = 4;
      }
      else if (c == 'M') { // midi command
        state = 4;
      }
      else if (c == 'B') { // virtual Axoloti Control buttons
        state = 4;
      }
      else if (c == 'C') { // create sdcard file
        state = 4;
      }
      else if (c == 'A') { // append data to sdcard file
        state = 4;
      }
      else if (c == 'r') { // generic read
        state = 4;
      }
      else if (c == 'y') { // generic read
        state = 4;
      }
      else if (c == 'S') { // stop patch
        state = 0;
        header = 0;
        StopPatch();
        AckPending = 1;
      }
      else if (c == 'D') { // go to DFU mode
        state = 0;
        header = 0;
        StopPatch();
        exception_initiate_dfu();
      }
      else if (c == 'F') { // copy to flash
        state = 0;
        header = 0;
        StopPatch();
        CopyPatchToFlash();
      }
      else if (c == 'd') { // read directory listing
        state = 0;
        header = 0;
        StopPatch();
        ReadDirectoryListing();
      }
      else if (c == 's') { // start patch
        state = 0;
        header = 0;
        loadPatchIndex = LIVE;
        StartPatch();
        AckPending = 1;
      }
      else if (c == 'V') { // FW version number
        state = 0;
        header = 0;
        ReplyFWVersion();
        AckPending = 1;
      }
      else if (c == 'p') { // ping
        state = 0;
        header = 0;
#ifdef DEBUG_SERIAL
        chprintf((BaseSequentialStream * )&SD2,"ping\r\n");
#endif
        AckPending = 1;
      }
      else if (c == 'c') { // close sdcard file
        state = 0;
        header = 0;
        CloseFile();
        AckPending = 1;
      }
      else
        state = 0;
      break;
    }
  }
  else if (header == 'P') { // param change
    switch (state) {
    case 4:
      patchid = c;
      state++;
      break;
    case 5:
      patchid += c << 8;
      state++;
      break;
    case 6:
      patchid += c << 16;
      state++;
      break;
    case 7:
      patchid += c << 24;
      state++;
      break;
    case 8:
      value = c;
      state++;
      break;
    case 9:
      value += c << 8;
      state++;
      break;
    case 10:
      value += c << 16;
      state++;
      break;
    case 11:
      value += c << 24;
      state++;
      break;
    case 12:
      index = c;
      state++;
      break;
    case 13:
      index += c << 8;
      state = 0;
      header = 0;
      if ((patchid == patchMeta.patchID) &&
          (index < patchMeta.numPEx)) {
        PExParameterChange(&(patchMeta.pPExch)[index], value, 0xFFFFFFEE);
      }
      break;
    default:
      state = 0;
      header = 0;
    }
  }
  else if (header == 'W') {
    switch (state) {
    case 4:
      offset = c;
      state++;
      break;
    case 5:
      offset += c << 8;
      state++;
      break;
    case 6:
      offset += c << 16;
      state++;
      break;
    case 7:
      offset += c << 24;
      state++;
      break;
    case 8:
      value = c;
      state++;
      break;
    case 9:
      value += c << 8;
      state++;
      break;
    case 10:
      value += c << 16;
      state++;
      break;
    case 11:
      value += c << 24;
      state++;
      break;
    default:
      if (value > 0) {
        value--;
        *((unsigned char *)offset) = c;
        offset++;
        if (value == 0) {
          header = 0;
          state = 0;
          AckPending = 1;
        }
      }
      else {
        header = 0;
        state = 0;
        AckPending = 1;
      }
    }
  }
  else if (header == 'w') {
    switch (state) {
    case 4:
      offset = c;
      state++;
      break;
    case 5:
      offset += c << 8;
      state++;
      break;
    case 6:
      offset += c << 16;
      state++;
      break;
    case 7:
      offset += c << 24;
      state++;
      break;
    case 8:
      value = c;
      state++;
      break;
    case 9:
      value += c << 8;
      state++;
      break;
    case 10:
      value += c << 16;
      state++;
      break;
    case 11:
      value += c << 24;
      length = value;
      position = offset;
      state++;
      break;
    case 12:
    case 13:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    case 19:
    case 20:
    case 21:
    case 22:
    case 23:
      FileName[state - 12] = c;
      state++;
      break;
    default:
      if (value > 0) {
        value--;
        *((unsigned char *)position) = c;
        position++;
        if (value == 0) {
          FRESULT err;
          header = 0;
          state = 0;
          sdcard_attemptMountIfUnmounted();
          err = f_open(&pFile, &FileName[0], FA_WRITE | FA_CREATE_ALWAYS);
          if (err != FR_OK) {
            LogTextMessage("File open failed");
          }
          int bytes_written;
          err = f_write(&pFile, (char *)offset, length, (void *)&bytes_written);
          if (err != FR_OK) {
            LogTextMessage("File write failed");
          }
          err = f_close(&pFile);
          if (err != FR_OK) {
            LogTextMessage("File close failed");
          }
          AckPending = 1;
        }
      }
      else {
        header = 0;
        state = 0;
      }
    }
  }
  else if (header == 'T') { // Apply Preset
    ApplyPreset(c);
    AckPending = 1;
    header = 0;
    state = 0;
  }
  else if (header == 'M') { // Midi message
    static uint8_t midi_r[3];
    switch (state) {
    case 4:
      midi_r[0] = c;
      state++;
      break;
    case 5:
      midi_r[1] = c;
      state++;
      break;
    case 6:
      midi_r[2] = c;
      MidiInMsgHandler(MIDI_DEVICE_INTERNAL, 1, midi_r[0], midi_r[1],
                       midi_r[2]);
      header = 0;
      state = 0;
      break;
    default:
      header = 0;
      state = 0;
    }
  }
  else if (header == 'C') {
    switch (state) {
    case 4:
      pFileSize = c;
      state++;
      break;
    case 5:
      pFileSize += c << 8;
      state++;
      break;
    case 6:
      pFileSize += c << 16;
      state++;
      break;
    case 7:
      pFileSize += c << 24;
      state++;
      break;
    case 8:
      FileName[state - 8] = c;
      // filename starting with null means there are attributes present
      state++;
      break;
    default:
      if (c || ((!FileName[0])&&(state<14))) {
        FileName[state - 8] = c;
        state++;
      }
      else {
        FileName[state - 8] = 0;
        ManipulateFile();
        header = 0;
        state = 0;
        AckPending = 1;
      }
    }
  }
  else if (header == 'A') {
    switch (state) {
    case 4:
      value = c;
      state++;
      break;
    case 5:
      value += c << 8;
      state++;
      break;
    case 6:
      value += c << 16;
      state++;
      break;
    case 7:
      value += c << 24;
      length = value;
      position = PATCHMAINLOC;
      state++;
      break;
    default:
      if (value > 0) {
        value--;
        *((unsigned char *)position) = c;
        position++;
        if (value == 0) {
          FRESULT err;
          header = 0;
          state = 0;
          int bytes_written;
          err = f_write(&pFile, (char *)PATCHMAINLOC, length,
                        (void *)&bytes_written);
          if (err != FR_OK) {
            report_fatfs_error(err,0);
          }
          AckPending = 1;
        }
      }
      else {
        header = 0;
        state = 0;
      }
    }
  }
  else if (header == 'B') {
    switch (state) {
    case 4:
      a = c;
      state++;
      break;
    case 5:
      a += c << 8;
      state++;
      break;
    case 6:
      a += c << 16;
      state++;
      break;
    case 7:
      a += c << 24;
      state++;
      break;
    case 8:
      b = c;
      state++;
      break;
    case 9:
      b += c << 8;
      state++;
      break;
    case 10:
      b += c << 16;
      state++;
      break;
    case 11:
      b += c << 24;
      state++;
      break;
    case 12:
      EncBuffer[0] += c;
      state++;
      break;
    case 13:
      EncBuffer[1] += c;
      state++;
      break;
    case 14:
      EncBuffer[2] += c;
      state++;
      break;
    case 15:
      EncBuffer[3] += c;
      header = 0;
      state = 0;
      Btn_Nav_Or.word = Btn_Nav_Or.word | a;
      Btn_Nav_And.word = Btn_Nav_And.word & b;
      break;
    }
  }
  else if (header == 'R') {
    switch (state) {
    case 4:
      length = c;
      state++;
      break;
    case 5:
      length += c << 8;
      state++;
      break;
    case 6:
      length += c << 16;
      state++;
      break;
    case 7:
      length += c << 24;
      state++;
      offset = (int)patchMeta.pPresets;
      break;
    default:
      if (length > 0) {
        length--;
        if (offset) {
          *((unsigned char *)offset) = c;
          offset++;
        }
        if (length == 0) {
          header = 0;
          state = 0;
          AckPending = 1;
        }
      }
      else {
        header = 0;
        state = 0;
        AckPending = 1;
      }
    }
  }
  else if (header == 'r') { // generic read
    switch (state) {
    case 4:
      offset = c;
      state++;
      break;
    case 5:
      offset += c << 8;
      state++;
      break;
    case 6:
      offset += c << 16;
      state++;
      break;
    case 7:
      offset += c << 24;
      state++;
      break;
    case 8:
      value = c;
      state++;
      break;
    case 9:
      value += c << 8;
      state++;
      break;
    case 10:
      value += c << 16;
      state++;
      break;
    case 11:
      value += c << 24;

      uint32_t read_repy_header[3];
      ((char*)read_repy_header)[0] = 'A';
      ((char*)read_repy_header)[1] = 'x';
      ((char*)read_repy_header)[2] = 'o';
      ((char*)read_repy_header)[3] = 'r';
      read_repy_header[1] = offset;
      read_repy_header[2] = value;
      chSequentialStreamWrite((BaseSequentialStream * )&BDU1,
                              (const unsigned char* )(&read_repy_header[0]), 3 * 4);
      chSequentialStreamWrite((BaseSequentialStream * )&BDU1,
                              (const unsigned char* )(offset), value);

      AckPending = true;
      header = 0;
      state = 0;
      break;
    }
  }
  else if (header == 'y') { // generic read, 32bit
    switch (state) {
    case 4:
      offset = c;
      state++;
      break;
    case 5:
      offset += c << 8;
      state++;
      break;
    case 6:
      offset += c << 16;
      state++;
      break;
    case 7:
      offset += c << 24;

      uint32_t read_repy_header[3];
      ((char*)read_repy_header)[0] = 'A';
      ((char*)read_repy_header)[1] = 'x';
      ((char*)read_repy_header)[2] = 'o';
      ((char*)read_repy_header)[3] = 'y';
      read_repy_header[1] = offset;
      read_repy_header[2] = *((uint32_t*)offset);
      chSequentialStreamWrite((BaseSequentialStream * )&BDU1,
                              (const unsigned char* )(&read_repy_header[0]), 3 * 4);

      AckPending = true;
      header = 0;
      state = 0;
      break;
    }
  }  else {
    header = 0;
    state = 0;
  }
}
Exemple #4
0
bool PPatchServer::HandleFileRequests(PClient *Client, PPatchState *State, const u8 *Packet, int PacketSize)
{
	static u8 STARTPATCH[13]={0xfe, 0x0a, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	static u8 STARTFILE[13]={0xfe, 0x0a, 0x00, 0x3b, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	static u8 FILEERROR[9]={0xfe, 0x06, 0x00, 0x3d, 0x02, 0x00, 0x00, 0x00, 0x00};

	ConnectionTCP *Socket = Client->getTCPConn();
	// request patch
	if(PacketSize==13 && *(u16*)&Packet[3]==0x007c)
	{
		int nmax = Config->GetOptionInt("max_file_xfers");
		if(mNumFileTransfers>=nmax)
		{
			Console->Print("Patchserver: max file xfers exceed, killing client %i", Client->GetIndex());
			return false;
		}
		if(State->mPatchFile)
		{
			std::fclose(State->mPatchFile);
			State->mPatchFile=0;
			--mNumFileTransfers;
		}
		if(State->mSendFile)
		{
			Filesystem->Close(State->mSendFile);
			State->mSendFile=0;
			--mNumFileTransfers;
		}
		State->mSerial = *(u16*)&Packet[7];
		State->mCurrentPatch = *(u32*)&Packet[9];
		Console->Print("Patchserver: Patch request from client %i (v%i)", Client->GetIndex(), State->mCurrentPatch);
		if((bool)(State->mPatchSize = StartPatch(State)))
		{
			Console->Print("Patchserver: Patch is available, %d bytes", State->mPatchSize);
			*(u16*)&STARTPATCH[7]=State->mSerial;
			*(u32*)&STARTPATCH[9]=State->mPatchSize;
			Socket->write(STARTPATCH, 13);
			State->mState = PPatchState::PS_SENDPATCH;
		} else
		{
			Console->Print("Patchserver: Patch not available");
			*(u16*)&FILEERROR[7]=State->mSerial;
			Socket->write(FILEERROR, 9);
			FinalizeClientDelayed(Client, State);
			State->mState=PPatchState::PS_UNKNOWN;
			return true;
		}
	} else
	// request file
	if(PacketSize > 9 && *(u16*)&Packet[3]==0x004d)
	{
		int nmax = Config->GetOptionInt("max_file_xfers");
		if(mNumFileTransfers>=nmax)
		{
			Console->Print("Patchserver: max file xfers exceed, killing client %i", Client->GetIndex());
			return false;
		}
		if(State->mPatchFile)
		{
			std::fclose(State->mPatchFile);
			State->mPatchFile=0;
			--mNumFileTransfers;
		}
		if(State->mSendFile)
		{
			Filesystem->Close(State->mSendFile);
			State->mSendFile=0;
			--mNumFileTransfers;
		}
		// request file
		State->mSerial = *(u16*)&Packet[7];
		char fn[256];
		strncpy(fn, (const char*)&Packet[10], Packet[9]);
		fn[Packet[9]]=0;
		State->mCurrentFile = fn;

		Console->Print("Patchserver: File request from client %i (%s)", Client->GetIndex(), fn);
		if((bool)(State->mFileSize = StartFile(State)))
		{
			Console->Print("Patchserver: File %s is available, %d bytes", State->mCurrentFile.c_str(), State->mFileSize);
			*(u16*)&STARTFILE[7]=State->mSerial;
			*(u32*)&STARTFILE[9]=State->mFileSize;
			Socket->write(STARTFILE, 13);
			State->mState = PPatchState::PS_SENDFILE;
		} else
		{
			Console->Print("Patchserver: Requested file %s not available", State->mCurrentFile.c_str());
			*(u16*)&FILEERROR[7]=State->mSerial;
			Socket->write(FILEERROR, 9);
			FinalizeClientDelayed(Client, State);
			State->mState=PPatchState::PS_UNKNOWN;
			return true;
		}
	} else
	// send patch data
	if(PacketSize==17 && *(u16*)&Packet[3]==0x007d)
	{
		State->mSerial = *(u16*)&Packet[7];
		State->mCurrentPatch = *(u32*)&Packet[9];
		State->mPatchOffset = *(u32*)&Packet[13];
		if(!SendPatchData(Client, State))
		{
			Console->Print("Patchserver: SendPatchData failed on client %i", Client->GetIndex());
			Console->Print("Patchserver: (probably due to garbage packets)");
			// state is undefined now, kill this client
			return false;
		}
	} else
	// send file data
	if(PacketSize > 13 && *(u16*)&Packet[3]==0x00037)
	{
		State->mSerial = *(u16*)&Packet[7];
		State->mFileOffset = *(u32*)&Packet[9];
		if(!SendFileData(Client, State))
		{
			Console->Print("Patchserver: SendFileData failed on client %i", Client->GetIndex());
			Console->Print("Patchserver: (probably due to garbage packets)");
			// state is undefined now, kill this client
			return false;
		}
	} else
	{
		Console->Print("Patchserver protocol error (PS_GETPATCHORFILE): unknown packet");
		return false;
	}

	return true;
}
Exemple #5
0
int main(void) {
  // copy vector table to SRAM1!
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
  memcpy((char *)0x20000000, (const char)0x00000000, 0x200);
#pragma GCC diagnostic pop
  // remap SRAM1 to 0x00000000
  SYSCFG->MEMRMP |= 0x03;

  halInit();
  chSysInit();

  sdcard_init();
  sysmon_init();

#if ENABLE_SERIAL_DEBUG
// SD2 for serial debug output
  palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7) | PAL_MODE_INPUT); // RX
  palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL); // TX
  palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); // TX
// 115200 baud
  static const SerialConfig sd2Cfg = {115200,
        0, 0, 0};
  sdStart(&SD2, &sd2Cfg);
  chprintf((BaseSequentialStream * )&SD2,"Hello world!\r\n");
#endif

  exception_init();

  InitPatch0();

  InitPConnection();

  InitPWM();

  // display SPI CS?
  palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPad(GPIOC, 1);

  chThdSleepMilliseconds(10);

  palSetPadMode(SW2_PORT, SW2_PIN, PAL_MODE_INPUT_PULLDOWN);

  axoloti_board_init();
  codec_init();
  if (!palReadPad(SW2_PORT, SW2_PIN)) { // button S2 not pressed
//    watchdog_init();
    chThdSleepMilliseconds(1);
  }
  start_dsp_thread();
  adc_init();
  axoloti_math_init();
  midi_init();

#if ((BOARD_AXOLOTI_V03)||(BOARD_AXOLOTI_V05))
  axoloti_control_init();
#endif
  ui_init();
  StartLoadPatchTread();

#if (BOARD_AXOLOTI_V05)
  configSDRAM();
  //memTest();
#endif

#ifdef ENABLE_USB_HOST
  MY_USBH_Init();
#endif

  if (!exception_check()) {
    // only try booting a patch when no exception is to be reported

#if ((BOARD_AXOLOTI_V03)||(BOARD_AXOLOTI_V05))
    sdcard_attemptMountIfUnmounted();
    if (fs_ready && !palReadPad(SW2_PORT, SW2_PIN)){
      // button S2 not pressed
      FRESULT res;
//      res = f_stat("/start.bin", NULL);
//      if (res == FR_OK) {
        LoadPatch("/start.bin");
//      }
    }
#endif

    // if no patch booting or running yet
    // try loading from flash
    if (patchStatus) {
      // patch in flash sector 11
      memcpy((uint8_t *)PATCHMAINLOC, (uint8_t *)PATCHFLASHLOC, PATCHFLASHSIZE);
      if ((*(uint32_t *)PATCHMAINLOC != 0xFFFFFFFF)
          && (*(uint32_t *)PATCHMAINLOC != 0)) {
        if (!palReadPad(SW2_PORT, SW2_PIN)) // button S2 not pressed
          StartPatch();
      }
    }
  }

  while (1) {
    chThdSleepMilliseconds(1000);
  }
}