Exemplo n.º 1
0
void EVENT_USB_Device_ControlRequest(void) {
    HID_Device_ProcessControlRequest(&mouseHIDInterface);
}
Exemplo n.º 2
0
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
	HID_Device_ProcessControlRequest(&MediaControl_HID_Interface);
}
Exemplo n.º 3
0
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
    CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
    HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
}
Exemplo n.º 4
0
/* Event handler for the library USB Control Request reception event */
void EVENT_USB_Device_ControlRequest(void)
{
	HID_Device_ProcessControlRequest(&Generic_HID_Interface);
}
Exemplo n.º 5
0
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
	HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
}
Exemplo n.º 6
0
/** Event handler for the library USB Unhandled Control Request event. */
void EVENT_USB_Device_UnhandledControlRequest(void)
{
    HID_Device_ProcessControlRequest(&Joystick_HID_Interface);
}
Exemplo n.º 7
0
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
  CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
  HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
  MS_Device_ProcessControlRequest(&Disk_MS_Interface);
}
Exemplo n.º 8
0
/** Event handler for the library USB Unhandled Control Request event. */
void EVENT_USB_Device_UnhandledControlRequest(void)
{
	HID_Device_ProcessControlRequest(&Mouse_HID_Device_Interface);
}
Exemplo n.º 9
0
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
  static uint8_t success = 1;

  uint8_t bmRequestType = USB_ControlRequest.bmRequestType;
  uint8_t bRequest      = USB_ControlRequest.bRequest;
  //uint8_t wValue        = USB_ControlRequest.wValue;
  char data[51];

  HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);

  if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE))
  {
    char lock;
    uint16_t wLength = USB_ControlRequest.wLength;
    char pw[32];
    success = 1; /* default */

    eeprom_read(ADDR_LOCK, &lock, 1);
    if(lock == 0 || lock == 255)
      lock = 0;
    else
    {
      if(bRequest != OPENKUBUS_GET_NONCE && bRequest != OPENKUBUS_SET_TIMESTAMP && bRequest != OPENKUBUS_RESET)
      {
        success = 0;
        return;
      }
    }

    // read data
    if(wLength)
    {
      Endpoint_ClearSETUP();
      Endpoint_Read_Control_Stream_LE(data, MIN(sizeof(data), wLength));
      Endpoint_ClearIN();
    }

    switch(bRequest)
    {
      case OPENKUBUS_SET_LOCK:
        lock = 1;
        eeprom_write(ADDR_LOCK, &lock, 1);
        break;

      
      case OPENKUBUS_SET_OWNER:
        if(wLength)
          eeprom_write(ADDR_OWNER, data, wLength);
        else
          success = 0;
        
        break;
      

      case OPENKUBUS_SET_COMPANY:
        if(wLength)
          eeprom_write(ADDR_COMPANY, data, wLength);
        else
          success = 0;
        
        break;
      

      case OPENKUBUS_SET_DESCRIPTION:
        if(wLength)
          eeprom_write(ADDR_DESCRIPTION, data, wLength);
        else
          success = 0;
        
        break;


      case OPENKUBUS_SET_ID:
        if(wLength == 4)
          eeprom_write(ADDR_ID, data, wLength);
        else
          success = 0;
        
        break;


      case OPENKUBUS_SET_TIMESTAMP:
        if(wLength == 16)
        {
          aes256_ctx_t ctx;

          memset(&ctx, 0, sizeof(aes256_ctx_t));
          eeprom_read(ADDR_SEED, pw, sizeof(pw));

          aes256_init(pw, &ctx);
          aes256_dec(data, &ctx);

          if(strncmp(nonce, data, sizeof(nonce)) == 0)
          {
            set_timestamp(array2int((uint8_t *)&data[12]));
            update_nonce();
          }
          else
            success = 0;
        }
        else
          success = 0;

        break;


      case OPENKUBUS_RESET:
        if(wLength == 16)
        {
          aes256_ctx_t ctx;

          memset(&ctx, 0, sizeof(aes256_ctx_t));
          memcpy_P(pw, MASTER_PASSWORD, sizeof(pw));

          aes256_init(pw, &ctx);
          aes256_dec(data, &ctx);

          if(strncmp(nonce, data, sizeof(nonce)) == 0)
          {
            clear_eeprom();
            wdt_enable(WDTO_15MS);
            while(1);
          }
          else
            success = 0;
        }
        else
          success = 0;

        break;


      case OPENKUBUS_SET_SEED:
        if(wLength == LEN_SEED)
          eeprom_write(ADDR_SEED, data, LEN_SEED);
        else
          success = 0;

        break;


      case OPENKUBUS_SET_COUNTER:
        if(wLength == LEN_COUNTER)
          eeprom_write(ADDR_COUNTER, data, LEN_COUNTER);
        else
          success = 0;

        break;


      default:
        success = 0;
        break;
    }
  }
  else if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE))
  {
    uint8_t length = 0;
    uint8_t i;
    uint32_t temp32 = 0;
    char c;

    switch(bRequest)
    {
      case OPENKUBUS_GET_SUCCESS:
        data[length++] = success;
        break;


      case OPENKUBUS_GET_NONCE:
        for(i = 0; i < sizeof(nonce); i++)
          data[length++] = nonce[i];

        break;


      case OPENKUBUS_GET_TEMPERATURE:
        #ifdef RTC
          data[length++] = rtc_get_temperature();
        #else
          data[length++] = 0xFF;
        #endif
        break;


      case OPENKUBUS_GET_ID:
        for(i = 0; i < LEN_ID; i++)
        {
          eeprom_read(ADDR_ID+i, &c, 1); 
          data[length++] = c;
        }

        break;


      case OPENKUBUS_GET_TIME:
        temp32 = get_timestamp();

        data[length++] = temp32 >> 24;
        data[length++] = temp32 >> 16;
        data[length++] = temp32 >> 8;
        data[length++] = temp32;
        break;


      case OPENKUBUS_GET_SERIAL:
        for(i = 0x0e; i <= 0x18; i++)
          data[length++] = boot_signature_byte_get(i);
        break;


      case OPENKUBUS_GET_DESCRIPTION:
        for(i = 0; i < LEN_DESCRIPTION; i++)
        {
          eeprom_read(ADDR_DESCRIPTION+i, &c, 1); 
          data[length++] = c;
          if(c == 0)
            break;
        }

        break;


      case OPENKUBUS_GET_COMPANY:
        for(i = 0; i < LEN_COMPANY; i++)
        {
          eeprom_read(ADDR_COMPANY+i, &c, 1); 
          data[length++] = c;
          if(c == 0)
            break;
        }

        break;


      case OPENKUBUS_GET_OWNER:
        for(i = 0; i < LEN_OWNER; i++)
        {
          eeprom_read(ADDR_OWNER+i, &c, 1); 
          data[length++] = c;
          if(c == 0)
            break;
        }

        break;

      default:
        data[length++] = 0;
    }

    // send data
    Endpoint_ClearSETUP();
    Endpoint_Write_Control_Stream_LE(data, length);
    Endpoint_ClearOUT();
  }