USB_Config_Vendor/AES_KEY/include/AES_USB.h

110 lines
3.0 KiB
C
Raw Normal View History

2026-02-03 14:36:30 +08:00
#ifndef AES_USB_COMM_H
#define AES_USB_COMM_H
#include <string>
#include "vector"
#include "stdint.h"
#ifdef __OHOS__
#include <usb/usb_ddk_api.h>
#include <usb/usb_ddk_types.h>
#include "hid/hid_ddk_api.h"
#include "hid/hid_ddk_types.h"
#else
#endif
#define AES_BUFFER_MAX 60
typedef uint8_t AES_Buffer;
class AES_USB {
class HIDDevice;
HIDDevice* hidDevice;
typedef enum {
// 缓冲区过大或错误,缓冲区最大60字节
BUFFER_MAX_ERROR = -2,
// 设备不存在
DEVICE_NOT_EXIST = -1,
// UserPIN 错误
DEVICE_USER_PIN_ERROR = -3,
} HID_ERROR;
char devicePIN[21];
public:
typedef struct OH_USB_Driver{
int32_t vendor_id;
int32_t product_id;
int64_t deviceId;
}OH_USB_Driver;
/**
* @brief USB
* @return int 0 -1
*/
static int init();
/**
* @brief USB
*/
static void release();
AES_USB();
~AES_USB();
/**
* @brief
* @param vendor_id VID
* @param product_id PID
* @param drivers USB列表(鸿)
* @return int 1 -1
*/
int open(uint16_t vendor_id, uint16_t product_id,const std::vector<OH_USB_Driver>& drivers = std::vector<OH_USB_Driver>()) const;
/**
* @brief PIN
* @param pin PIN
* @return PIN结果 0: 1: -1: PIN长度错误
*/
int setUserPIN(const std::string& pin);
/**
* @brief VID和PID
* @param vendor_id VID
* @param product_id PID
* @return int 0 -1
*/
int set_vid_pid(uint16_t vendor_id, uint16_t product_id) const;
/**
* @brief VID和PID值
* @param vendor_id VID
* @param product_id PID
* @return int 1: -1:
*/
int read_vid_pid(uint16_t* vendor_id, uint16_t* product_id) const;
/**
* @brief
* @param data
* @param length
* @param timeout
* @return int32_t 0 0 -> HID_ERROR
*/
int32_t write(uint8_t* data, int length, int timeout = 1000 * 1000) const;
/**
* @brief
* @param data
* @param length
* @param timeout
* @return int32_t 0 0 -> HID_ERROR
*/
int32_t read(uint8_t* data, int length, int timeout = 1000 * 1000) const;
/**
* @brief
*/
void close() const;
//---------------厂家函数------------------------------------------------------------------------------
static int resetAll();
typedef struct PID_Key {
uint16_t vendor_id;
uint16_t product_id;
uint8_t PIN[20];
} PID_Key;
static int readID_Pin(PID_Key* key);
static int writeID_Pin(const PID_Key* key);
//---------------厂家函数------------------------------------------------------------------------------
};
#endif