1# Peripheral Management Module Changelog 2 3## cl.usbddk.1 Change in the Return Value When Incorrect Parameters Are Passed to SendPipeRequest and SendPipeRequestWithAshmem 4 5**Access Level** 6 7Public API 8 9**Reason for the Change** 10 11When **OH_Usb_SendPipeRequest** or **OH_Usb_SendPipeRequestWithAshmem** is called, if the length of **bufferlen** in **devMmap** is greater than the value of **MaxPacketSize**, the API call fails but no error is reported. 12 13**Change Impact** 14 15This change does not require application adaptation. 16 17Before change: If data transfer is interrupted because incorrect parameters are passed to **OH_Usb_SendPipeRequest** or **OH_Usb_SendPipeRequestWithAshmem**, the API call fails but no error is reported. 18 19After change: If data transfer is interrupted because incorrect parameters are passed to **OH_Usb_SendPipeRequest** or **OH_Usb_SendPipeRequestWithAshmem**, the API call fails and an error is reported. 20 21**Start API Level** 22 23SendPipeRequest : API version 10 24 25SendPipeRequestWithAshmem: API version 12 26 27**Change Since** 28 29OpenHarmony 6.0.0.32. 30 31**Key API/Component Changes** 32 33drivers/external_device_manager: OH_Usb_SendPipeRequest and OH_Usb_SendPipeRequestWithAshmem 34 35**Adaptation Guide** 36 37The API functions remain unchanged as long as correct parameters are passed to **OH_Usb_SendPipeRequest** and **OH_Usb_SendPipeRequestWithAshmem**. Therefore, adaptation is not required. 38 39Sample code: 40 41```C 42 ... 43 static uint8_t g_configIndex = 0; 44 static uint64_t g_interfaceHandle = 0; 45 static std::tuple<bool, uint8_t, uint8_t, uint16_t> FindForEachInterface(const UsbDdkInterface &interface) 46 { 47 struct UsbDdkInterfaceDescriptor *intDesc = interface.altsetting; 48 uint32_t numSetting = interface.numAltsetting; 49 for (uint32_t setIdx = PARAM_0; setIdx < numSetting; ++setIdx) { 50 uint32_t numEp = intDesc[setIdx].interfaceDescriptor.bNumEndpoints; 51 struct UsbDdkEndpointDescriptor *epDesc = intDesc[setIdx].endPoint; 52 for (uint32_t epIdx = PARAM_0; epIdx < numEp; ++epIdx) { 53 if (!IsInterruptInEndpoint(epDesc[epIdx].endpointDescriptor)) { 54 continue; 55 } 56 return { true, intDesc[setIdx].interfaceDescriptor.bInterfaceNumber, 57 epDesc[epIdx].endpointDescriptor.bEndpointAddress, epDesc[epIdx].endpointDescriptor.wMaxPacketSize }; 58 } 59 } 60 return { false, {}, {}, {} }; 61 } 62 63 static std::tuple<bool, uint8_t, uint8_t, uint16_t> GetEndpointInfo(const struct UsbDdkConfigDescriptor *config) 64 { 65 for (uint32_t intIdx = PARAM_0; intIdx < config->configDescriptor.bNumInterfaces; ++intIdx) { 66 auto result = FindForEachInterface(config->interface[intIdx]); 67 if (std::get<0>(result)) { 68 return result; 69 } 70 } 71 return { false, {}, {}, {} }; 72 } 73 74 struct UsbDdkConfigDescriptor *config = nullptr; 75 // Obtain the device ID by calling the ArkTS queryDevice. 76 int32_t ret = OH_Usb_GetConfigDescriptor(deviceId, g_configIndex, &config); 77 if (ret != USB_DDK_SUCCESS) { 78 // Print the error information for the OH_Usb_GetConfigDescriptor call failure. 79 return; 80 } 81 82 // Obtain the value of maxPktSize by parsing config. 83 auto [result, interface, endpoint, maxPktSize] = GetEndpointInfo(config); 84 if (!result) { 85 // Print the error information for the GetEndpointInfo call failure. 86 return; 87 } 88 89 ret = OH_Usb_ClaimInterface(deviceId, interface, &g_interfaceHandle); 90 if (ret != USB_DDK_SUCCESS) { 91 // Print the error information for the OH_Usb_ClaimInterface call failure. 92 return; 93 } 94 95 // Call OH_Usb_SendPipeRequest. 96 struct UsbDeviceMemMap *devMemMap = nullptr; 97 size_t bufferLen = maxPktSize; 98 ret = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap); 99 if (ret != USB_DDK_SUCCESS) { 100 // Print the error information for the OH_Usb_CreateDeviceMemMap call failure. 101 return; 102 } 103 struct UsbRequestPipe pipe; 104 pipe.interfaceHandle = g_interfaceHandle; 105 pipe.endpoint = endpoint; 106 pipe.timeout = UINT32_MAX; 107 ret = OH_Usb_SendPipeRequest(&pipe, devMemMap); 108 ... 109 110 // Call OH_Usb_SendPipeRequestWithAshmem. 111 size_t bufferLen = maxPktSize; 112 const uint8_t name[100] = "TestAshmem"; 113 DDK_Ashmem *ashmem = nullptr; 114 int32_t result = OH_DDK_CreateAshmem(name, bufferLen, &ashmem); 115 if (result != USB_DDK_SUCCESS) { 116 // Print the error information for the OH_DDK_CreateAshmem call failure. 117 return; 118 } 119 const uint8_t ashmemMapType = 0x03; 120 result = OH_DDK_MapAshmem(ashmem, ashmemMapType); 121 if (result != USB_DDK_SUCCESS) { 122 // Print the error information for the OH_DDK_MapAshmem call failure. 123 return; 124 } 125 struct UsbRequestPipe pipe; 126 pipe.interfaceHandle = g_interfaceHandle; 127 pipe.endpoint = endpoint; 128 pipe.timeout = UINT32_MAX; 129 int32_t returnValue = OH_Usb_SendPipeRequestWithAshmem(&pipe, ashmem); 130 ... 131``` 132