mirror of
https://github.com/openharmony/drivers_peripheral.git
synced 2026-08-24 18:15:56 -04:00
@@ -59,19 +59,22 @@ static bool IsDir(const char *path)
|
||||
|
||||
static void GetFilePath(const char *path, const char *fileName, char *filePath)
|
||||
{
|
||||
int ret;
|
||||
ret = strcpy_s(filePath, MAX_PATHLEN - 1, path);
|
||||
if (ret) {
|
||||
HDF_LOGE("%s: strcpy_s failure!", __func__);
|
||||
int32_t ret = strcpy_s(filePath, MAX_PATHLEN - 1, path);
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s: strcpy_s failure!", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (filePath[strlen(path) - 1] != '/') {
|
||||
ret = strcat_s(filePath, MAX_PATHLEN - 1, "/");
|
||||
if (ret) {
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s: strcat_s failure!", __func__);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ret = strcat_s(filePath, MAX_PATHLEN - 1, fileName);
|
||||
if (ret) {
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s: strcat_s failure!", __func__);
|
||||
}
|
||||
}
|
||||
@@ -388,21 +391,19 @@ static int UsbFnAdapterDelInterface(const char *interfaceName, int nameLen)
|
||||
|
||||
static int UsbFnAdapterOpenPipe(const char *interfaceName, int epIndex)
|
||||
{
|
||||
int ret;
|
||||
char epName[MAX_NAMELEN];
|
||||
int i;
|
||||
int ep = -1;
|
||||
if (interfaceName == NULL || epIndex < 0) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = snprintf_s(epName, MAX_NAMELEN, MAX_NAMELEN - 1, "/dev/functionfs/%s.ep%u", interfaceName, epIndex);
|
||||
char epName[MAX_NAMELEN];
|
||||
int32_t ret = snprintf_s(epName, MAX_NAMELEN, MAX_NAMELEN - 1, "/dev/functionfs/%s.ep%d", interfaceName, epIndex);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("%s: snprintf_s failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
for (i = 0; i < OPEN_CNT; i++) {
|
||||
int ep = -1;
|
||||
for (int32_t i = 0; i < OPEN_CNT; i++) {
|
||||
ep = open(epName, O_RDWR);
|
||||
if (ep > 0) {
|
||||
break;
|
||||
|
||||
@@ -63,26 +63,26 @@ static int UsbFnAdapterClosefn(int fd)
|
||||
static int UsbFnAdapterCreateFconfigString(struct FconfigString *configString,
|
||||
const char *name)
|
||||
{
|
||||
int strLen;
|
||||
int ret;
|
||||
|
||||
if (configString == NULL || name == NULL) {
|
||||
HDF_LOGE("%s: configName is NULL", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
strLen = strlen(name);
|
||||
|
||||
int32_t strLen = strlen(name);
|
||||
configString->len = strLen;
|
||||
configString->s = UsbFnMemCalloc(strLen + 1);
|
||||
if (configString->s == NULL) {
|
||||
HDF_LOGE("%s: UsbFnMemCalloc failure!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
ret = memcpy_s(configString->s, (strLen + 1), name, strLen);
|
||||
if (ret) {
|
||||
|
||||
int32_t ret = memcpy_s(configString->s, (strLen + 1), name, strLen);
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s: memcpy_s failure!", __func__);
|
||||
UsbFnMemFree(configString->s);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
*(configString->s + configString->len) = '\0';
|
||||
return 0;
|
||||
}
|
||||
@@ -107,26 +107,28 @@ static int UsbFnAdapterWriteGadget(int fd, int cmd,
|
||||
static int UsbFnAdapterWriteDevDesc(int fd, struct FconfigString *gadgetName,
|
||||
const struct UsbFnDeviceDesc *descriptor)
|
||||
{
|
||||
int ret;
|
||||
struct FconfigDevDesc devDesc;
|
||||
|
||||
if (gadgetName == NULL || descriptor == NULL) {
|
||||
HDF_LOGE("%s: udcName is NULL", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
devDesc.gadgetName.len = gadgetName->len;
|
||||
devDesc.gadgetName.s = gadgetName->s;
|
||||
ret = memcpy_s(&devDesc.devDesc, sizeof(devDesc.devDesc), descriptor->deviceDesc,
|
||||
int32_t ret = memcpy_s(&devDesc.devDesc, sizeof(devDesc.devDesc), descriptor->deviceDesc,
|
||||
sizeof(devDesc.devDesc));
|
||||
if (ret) {
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s: memcpy_s failure!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
ret = handle_ioctl(fd, FCONFIG_CMD_WRITE_DEV_DESC, &devDesc);
|
||||
if (ret) {
|
||||
HDF_LOGE("%s: ioctl failure!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ static int OsSubmitIsoRequest(struct UsbHostRequest *request)
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
numUrbs = (request->numIsoPackets + (MAX_ISO_PACKETS_PER_URB - 1)) / MAX_ISO_PACKETS_PER_URB;
|
||||
pUrbs = RawUsbMemCalloc(numUrbs * sizeof(*pUrbs));
|
||||
pUrbs = RawUsbMemCalloc(numUrbs * sizeof(struct UsbAdapterUrb*));
|
||||
if (pUrbs == NULL) {
|
||||
HDF_LOGE("%s:%d RawUsbMemCalloc pUrbs failed", __func__, __LINE__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
|
||||
@@ -813,7 +813,7 @@ static int OsSubmitIsoRequest(struct UsbHostRequest *request)
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
numUrbs = (request->numIsoPackets + (MAX_ISO_PACKETS_PER_URB - 1)) / MAX_ISO_PACKETS_PER_URB;
|
||||
pUrbs = RawUsbMemCalloc(numUrbs * sizeof(*pUrbs));
|
||||
pUrbs = RawUsbMemCalloc(numUrbs * sizeof(struct Async*));
|
||||
if (pUrbs == NULL) {
|
||||
DPRINTFN(0, "%s:%d RawUsbMemCalloc pUrbs failed", __func__, __LINE__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
|
||||
@@ -665,11 +665,14 @@ static int32_t UsbSerialWrite(struct UsbSerial *port, struct HdfSBuf *data)
|
||||
HDF_LOGE("%s: OsalMemCalloc failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
if (strcpy_s(buf, strlen(tmp) + 1, tmp)) {
|
||||
|
||||
int32_t ret = strcpy_s(buf, strlen(tmp) + 1, tmp);
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s: strcpy_s failed", __func__);
|
||||
OsalMemFree(buf);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
size = DataFifoWrite(&port->writeFifo, (uint8_t *)buf, strlen(buf));
|
||||
|
||||
if (port->acm) {
|
||||
|
||||
@@ -221,7 +221,7 @@ static int BeginProcess(unsigned char endPoint)
|
||||
return r;
|
||||
}
|
||||
|
||||
printf("test NO SDK endpoint:%d\n", endPoint);
|
||||
printf("test NO SDK endpoint:%u\n", endPoint);
|
||||
|
||||
for (i = 0; i < TEST_CYCLE; i++) {
|
||||
if (urb[i].inUse == 0) {
|
||||
|
||||
@@ -165,7 +165,13 @@ static enum speedServer checkServer(const char* input)
|
||||
out = SDKAPI_SERVER;
|
||||
return out;
|
||||
}
|
||||
strncpy_s(middle, sizeof(middle), input, strlen(input));
|
||||
|
||||
int32_t ret = strncpy_s(middle, sizeof(middle), input, strlen(input));
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%s:%d strncpy_s failed", __func__, __LINE__);
|
||||
return out;
|
||||
}
|
||||
|
||||
if (!strcmp(middle, "-SDK")) {
|
||||
out = SDKAPI_SERVER;
|
||||
} else if (!strcmp(middle, "-RAW")) {
|
||||
|
||||
@@ -68,6 +68,7 @@ static void CloseDevice()
|
||||
{
|
||||
if (fd > 0) {
|
||||
close(fd);
|
||||
fd = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,13 @@ static void TestPnpWriteLog(char *string)
|
||||
|
||||
fp = fopen("/data/usbhost_pnp_xts", "a+");
|
||||
|
||||
(void)snprintf_s(str, STR_LEN, STR_LEN - 1, "[XTSCHECK] %d.%06d, %s\n",
|
||||
int32_t ret = snprintf_s(str, STR_LEN, STR_LEN - 1, "[XTSCHECK] %d.%06d, %s\n",
|
||||
time.tv_sec, time.tv_usec, string);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("%s: sbuf write failed", __func__);
|
||||
(void)fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
(void)fwrite(str, strlen(str), 1, fp);
|
||||
(void)fclose(fp);
|
||||
|
||||
@@ -483,7 +483,6 @@ static int SerialCtrlMsg(struct AcmDevice *acm, uint8_t request,
|
||||
static int SerialCtrlAsyncMsg(UsbInterfaceHandle *devHandle,
|
||||
struct UsbRequest *request, void *buf, uint16_t size)
|
||||
{
|
||||
int ret;
|
||||
const int offset = 8;
|
||||
struct UsbControlParams controlParams = {};
|
||||
struct UsbRequestParams parmas = {};
|
||||
@@ -507,8 +506,8 @@ static int SerialCtrlAsyncMsg(UsbInterfaceHandle *devHandle,
|
||||
parmas.requestType = USB_REQUEST_PARAMS_CTRL_TYPE;
|
||||
parmas.timeout = USB_CTRL_SET_TIMEOUT;
|
||||
parmas.ctrlReq = UsbControlSetUp(&controlParams);
|
||||
ret = UsbFillRequest(request, devHandle, &parmas);
|
||||
if (HDF_SUCCESS != ret) {
|
||||
int32_t ret = UsbFillRequest(request, devHandle, &parmas);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: faile, ret=%d ", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -522,7 +521,7 @@ static int SerialCtrlAsyncMsg(UsbInterfaceHandle *devHandle,
|
||||
for (unsigned int i = 0; i < request->compInfo.actualLength; i++)
|
||||
HDF_LOGE("0x%02x", ((uint8_t *)(request->compInfo.buffer))[i]);
|
||||
ret = memcpy_s(buf, size, request->compInfo.buffer, request->compInfo.actualLength);
|
||||
if (ret) {
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("memcpy_s fail\n");
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -672,7 +671,6 @@ static int SerialGetBaudrate(struct SerialDevice *port, struct HdfSBuf *reply)
|
||||
|
||||
static int32_t UsbSerialReadSync(const struct SerialDevice *port, const struct HdfSBuf *reply)
|
||||
{
|
||||
int ret;
|
||||
struct AcmDevice *acm = port->acm;
|
||||
uint8_t *data = NULL;
|
||||
struct UsbRequestParams readParmas = {};
|
||||
@@ -691,7 +689,7 @@ static int32_t UsbSerialReadSync(const struct SerialDevice *port, const struct H
|
||||
readParmas.dataReq.directon = (((uint8_t)acm->dataInPipe->pipeDirection) >> USB_DIR_OFFSET) & DIRECTION_MASK;
|
||||
readParmas.dataReq.length = acm->readSize;
|
||||
readParmas.callback = NULL;
|
||||
ret = UsbFillRequest(g_syncRequest, InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), &readParmas);
|
||||
int32_t ret = UsbFillRequest(g_syncRequest, InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), &readParmas);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
@@ -706,10 +704,13 @@ static int32_t UsbSerialReadSync(const struct SerialDevice *port, const struct H
|
||||
}
|
||||
HDF_LOGD("buffer:%p-%s-actualLength:%d", \
|
||||
g_syncRequest->compInfo.buffer, (uint8_t *)g_syncRequest->compInfo.buffer, count);
|
||||
|
||||
ret = memcpy_s(data, g_syncRequest->compInfo.actualLength, g_syncRequest->compInfo.buffer, count);
|
||||
if (ret) {
|
||||
HDF_LOGE("memcpy_s error");
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("memcpy_s error %s, %d", __func__, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteString((struct HdfSBuf *)reply, (const char *)data)) {
|
||||
HDF_LOGE("%s:%d sbuf write buffer failed", __func__, __LINE__);
|
||||
}
|
||||
@@ -717,6 +718,7 @@ static int32_t UsbSerialReadSync(const struct SerialDevice *port, const struct H
|
||||
OsalMemFree(data);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user