mirror of
https://gitee.com/openharmony/usb_usb_manager
synced 2024-11-23 06:40:24 +00:00
fix:usb inner review issue clear
Signed-off-by: wu-chengwen <wuchengwen4@huawei.com>
This commit is contained in:
parent
1386b9e795
commit
8c1bc389e8
104
OAT.xml
Normal file
104
OAT.xml
Normal file
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
<policyitem type="copyright" name="Huawei Technologies Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Huawei Technologies"/>
|
||||
<policyitem type="copyright" name="Huawei Device Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Huawei Device"/>
|
||||
<policyitem type="copyright" name="Rockchip Electronics Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed By Rockchip"/>
|
||||
<policyitem type="copyright" name="Shenzhen Kaihong DID Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Shenzhen Kaihong DID"/>
|
||||
<policyitem type="license" name="GPL" path=".*" desc="linux kernel adapter codes"/>
|
||||
<policyitem type="license" name="BSD" path=".*" desc="huawei codes"/>
|
||||
</policy>
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="*.lds|*.pod"/>
|
||||
<filteritem type="filename" name="*.a|*.d|*.o|*.so|*.cmd|*.hcb|*.swp"/>
|
||||
<filteritem type="filename" name="*.clang-format"/>
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filename" name="README.OpenSource"/>
|
||||
<filteritem type="filename" name="README"/>
|
||||
<filteritem type="filename" name="BUILD.gn"/>
|
||||
<filteritem type="filename" name="*.gni"/>
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies" >
|
||||
<filteritem type="filename" name="README.OpenSource"/>
|
||||
<filteritem type="filename" name="README"/>
|
||||
<filteritem type="filename" name="BUILD.gn"/>
|
||||
<filteritem type="filename" name="*.gni"/>
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies" >
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filename" name="BUILD.gn"/>
|
||||
<filteritem type="filename" name="*.gni"/>
|
||||
</filefilter>
|
||||
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies" >
|
||||
<filteritem type="filepath" name="README.md" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies" >
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
|
||||
<filteritem type="filepath" name="figures/.*.png" desc="USB architecture diagram"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
|
@ -10,7 +10,7 @@
|
||||
The following figure shows the USB service architecture.
|
||||
|
||||
**Figure 1** USB service architecture<a name="fig15658513184019"></a>
|
||||
![](usb.png "USB_service_architecture")
|
||||
![](figures/usb-manager-architecture.png "USB_service_architecture")
|
||||
|
||||
The architecture logically consists of three layers:
|
||||
1. USB API: provides USB APIs that implement various basic functions, for example, query of the USB device list, USB device plug notification, USB host and device mode switching, bulk transfer, control transfer, right management, and function switching in device mode.
|
||||
@ -52,7 +52,7 @@ base/usb/usb_manager
|
||||
| int32_t PipeRequestWait(USBDevicePipe &pip, int64_t timeout, UsbRequest &req); | Waits for the operation result of the isochronous transfer request in <b>RequestQueue</b>.|
|
||||
| int32_t RequestAbort(UsbRequest &request); | Cancels the data transfer requests to be processed.|
|
||||
| int32_t RequestFree(UsbRequest &request); | Requests for releasing data.|
|
||||
| int32_t HasRight(std::string deviceName); | Checks whether the application has permission to access the USB device.|
|
||||
| bool HasRight(std::string deviceName); | Checks whether the application has permission to access the USB device.|
|
||||
| int32_t RequestRight(std::string deviceName); | Requests for permission to access the USB device.|
|
||||
|
||||
#### Device APIs
|
||||
|
@ -10,7 +10,7 @@
|
||||
USB服务框架如下图所示:
|
||||
|
||||
**图 1** USB服务框架架图<a name="fig15658513184019"></a>
|
||||
![](usb服务子系统.png "USB服务框架架图")
|
||||
![](figures/usb-manager-architecture_zh.png "USB服务框架架图")
|
||||
|
||||
架构及功能介绍:
|
||||
1. USB API:提供USB的基础API,主要包含查询USB设备的列表、设备插拔通知、USB HOST/DEVICE 功能切换、批量数据传输、控制命令传输、USB设备打开的权限控制及USB device模式下的function功能切换等。
|
||||
@ -52,7 +52,7 @@ base/usb/usb_manager
|
||||
| int32_t PipeRequestWait(USBDevicePipe &pip, int64_t timeout, UsbRequest &req); | 等待RequestQueue异步请求的操作结果 |
|
||||
| int32_t RequestAbort(UsbRequest &request); | 取消待处理的数据请求 |
|
||||
| int32_t RequestFree(UsbRequest &request); | 释放数据请求 |
|
||||
| int32_t HasRight(std::string deviceName); | 判断设备是否有权限 |
|
||||
| bool HasRight(std::string deviceName); | 判断设备是否有权限 |
|
||||
| int32_t RequestRight(std::string deviceName); | 给指定设备申请权限 |
|
||||
|
||||
#### Device 功能接口
|
||||
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
@ -41,8 +41,6 @@ ohos_shared_library("usbsrv_client") {
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"device_driver_framework:libhdf_ipc_adapter",
|
||||
"device_driver_framework:libhdf_utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
};
|
||||
|
||||
virtual int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) = 0;
|
||||
virtual int32_t HasRight(std::string deviceName) = 0;
|
||||
virtual bool HasRight(std::string deviceName) = 0;
|
||||
virtual int32_t RequestRight(std::string deviceName) = 0;
|
||||
virtual int32_t RemoveRight(std::string deviceName) = 0;
|
||||
virtual int32_t GetDevices(std::vector<UsbDevice> &deviceList) = 0;
|
||||
|
@ -31,97 +31,97 @@ public:
|
||||
USBConfig(uint32_t id, uint32_t attributes, std::string name, uint32_t maxPower,
|
||||
std::vector<UsbInterface> interfaces)
|
||||
{
|
||||
this->id = id;
|
||||
this->attributes = attributes;
|
||||
this->maxPower = maxPower;
|
||||
this->name = name;
|
||||
this->interfaces = interfaces;
|
||||
this->id_ = id;
|
||||
this->attributes_ = attributes;
|
||||
this->maxPower_ = maxPower;
|
||||
this->name_ = name;
|
||||
this->interfaces_ = interfaces;
|
||||
}
|
||||
USBConfig() {}
|
||||
~USBConfig() {}
|
||||
|
||||
const int32_t &GetId() const
|
||||
{
|
||||
return id;
|
||||
return id_;
|
||||
}
|
||||
|
||||
const int32_t &GetAttributes() const
|
||||
{
|
||||
return attributes;
|
||||
return attributes_;
|
||||
}
|
||||
|
||||
bool GetInterface(uint32_t index, UsbInterface &interface) const
|
||||
{
|
||||
if (index >= interfaces.size()) {
|
||||
if (index >= interfaces_.size()) {
|
||||
return false;
|
||||
}
|
||||
interface = interfaces[index];
|
||||
interface = interfaces_[index];
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t GetInterfaceCount() const
|
||||
uint32_t GetInterfaceCount() const
|
||||
{
|
||||
return interfaces.size();
|
||||
return interfaces_.size();
|
||||
}
|
||||
|
||||
int32_t GetMaxPower() const
|
||||
{
|
||||
// 2 represent maxPower units
|
||||
return maxPower * 2;
|
||||
return maxPower_ * 2;
|
||||
}
|
||||
|
||||
const std::string &GetName() const
|
||||
{
|
||||
return name;
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool IsRemoteWakeup() const
|
||||
{
|
||||
return (attributes & USB_CFG_REMOTE_WAKEUP) != 0;
|
||||
return (attributes_ & USB_CFG_REMOTE_WAKEUP) != 0;
|
||||
}
|
||||
|
||||
bool IsSelfPowered() const
|
||||
{
|
||||
return (attributes & USB_CFG_SELF_POWERED) != 0;
|
||||
return (attributes_ & USB_CFG_SELF_POWERED) != 0;
|
||||
}
|
||||
|
||||
void SetInterfaces(const std::vector<UsbInterface> &interfaces)
|
||||
{
|
||||
this->interfaces = interfaces;
|
||||
this->interfaces_ = interfaces;
|
||||
}
|
||||
|
||||
std::vector<UsbInterface> &GetInterfaces()
|
||||
{
|
||||
return interfaces;
|
||||
return interfaces_;
|
||||
}
|
||||
|
||||
void SetId(int32_t id)
|
||||
{
|
||||
this->id = id;
|
||||
this->id_ = id;
|
||||
}
|
||||
|
||||
void SetAttribute(int32_t attributes)
|
||||
{
|
||||
this->attributes = attributes;
|
||||
this->attributes_ = attributes;
|
||||
}
|
||||
|
||||
void SetMaxPower(int32_t maxPower)
|
||||
{
|
||||
this->maxPower = maxPower;
|
||||
this->maxPower_ = maxPower;
|
||||
}
|
||||
|
||||
std::string ToString() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "name=" << name << ","
|
||||
<< "id=" << id << ","
|
||||
<< "iConfiguration=" << (int32_t)iConfiguration << ","
|
||||
<< "attributes=" << attributes << ","
|
||||
<< "maxPower=" << maxPower << "; ";
|
||||
ss << "name=" << name_ << ","
|
||||
<< "id=" << id_ << ","
|
||||
<< "iConfiguration=" << (int32_t)iConfiguration_ << ","
|
||||
<< "attributes=" << attributes_ << ","
|
||||
<< "maxPower=" << maxPower_ << "; ";
|
||||
std::string str = "USBConfig[" + ss.str() + "]";
|
||||
ss.str("");
|
||||
for (size_t i = 0; i < interfaces.size(); ++i) {
|
||||
const UsbInterface &interface = interfaces[i];
|
||||
for (size_t i = 0; i < interfaces_.size(); ++i) {
|
||||
const UsbInterface &interface = interfaces_[i];
|
||||
str += interface.ToString();
|
||||
}
|
||||
return str;
|
||||
@ -129,26 +129,26 @@ public:
|
||||
|
||||
void SetName(const std::string &name)
|
||||
{
|
||||
this->name = name;
|
||||
this->name_ = name;
|
||||
}
|
||||
|
||||
void SetiConfiguration(uint8_t idx)
|
||||
{
|
||||
this->iConfiguration = idx;
|
||||
this->iConfiguration_ = idx;
|
||||
}
|
||||
|
||||
uint8_t GetiConfiguration()
|
||||
{
|
||||
return this->iConfiguration;
|
||||
return this->iConfiguration_;
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t id = INVALID_USB_INT_VALUE;
|
||||
int32_t attributes = INVALID_USB_INT_VALUE;
|
||||
std::vector<UsbInterface> interfaces;
|
||||
int32_t maxPower = INVALID_USB_INT_VALUE;
|
||||
std::string name;
|
||||
uint8_t iConfiguration = UINT8_MAX;
|
||||
int32_t id_ = INVALID_USB_INT_VALUE;
|
||||
int32_t attributes_ = INVALID_USB_INT_VALUE;
|
||||
std::vector<UsbInterface> interfaces_;
|
||||
int32_t maxPower_ = INVALID_USB_INT_VALUE;
|
||||
std::string name_;
|
||||
uint8_t iConfiguration_ = UINT8_MAX;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -28,260 +28,290 @@ namespace OHOS {
|
||||
namespace USB {
|
||||
class UsbDevice {
|
||||
public:
|
||||
UsbDevice(std::string mName,
|
||||
std::string mManufacturerName,
|
||||
std::string mProductName,
|
||||
std::string mVersion,
|
||||
uint8_t devAddr,
|
||||
uint8_t busNum,
|
||||
int mVendorId,
|
||||
int mProductId,
|
||||
int mClass,
|
||||
int mSubclass,
|
||||
int mProtocol,
|
||||
std::vector<USBConfig> configs)
|
||||
UsbDevice(std::string name, std::string manufacturerName, std::string productName, std::string version,
|
||||
uint8_t devAddr, uint8_t busNum, int32_t vendorId, int32_t productId, int32_t klass, int32_t subClass,
|
||||
int32_t protocol, std::vector<USBConfig> configs)
|
||||
{
|
||||
this->mName = mName;
|
||||
this->mManufacturerName = mManufacturerName;
|
||||
this->mProductName = mProductName;
|
||||
this->mVersion = mVersion;
|
||||
this->devAddr = devAddr;
|
||||
this->busNum = busNum;
|
||||
this->mVendorId = mVendorId;
|
||||
this->mProductId = mProductId;
|
||||
this->mClass = mClass;
|
||||
this->mSubclass = mSubclass;
|
||||
this->mProtocol = mProtocol;
|
||||
this->configs = configs;
|
||||
this->name_ = name;
|
||||
this->manufacturerName_ = manufacturerName;
|
||||
this->productName_ = productName;
|
||||
this->version_ = version;
|
||||
this->devAddr_ = devAddr;
|
||||
this->busNum_ = busNum;
|
||||
this->vendorId_ = vendorId;
|
||||
this->productId_ = productId;
|
||||
this->klass_ = klass;
|
||||
this->subClass_ = subClass;
|
||||
this->protocol_ = protocol;
|
||||
this->configs_ = configs;
|
||||
}
|
||||
|
||||
UsbDevice() {}
|
||||
~UsbDevice() {}
|
||||
|
||||
const std::string &GetName() const
|
||||
{
|
||||
return mName;
|
||||
return name_;
|
||||
}
|
||||
|
||||
const std::string &GetManufacturerName() const
|
||||
{
|
||||
return mManufacturerName;
|
||||
return manufacturerName_;
|
||||
}
|
||||
|
||||
const std::string &GetProductName() const
|
||||
{
|
||||
return mProductName;
|
||||
return productName_;
|
||||
}
|
||||
|
||||
const std::string &GetVersion() const
|
||||
{
|
||||
return mVersion;
|
||||
return version_;
|
||||
}
|
||||
|
||||
int32_t GetVendorId() const
|
||||
{
|
||||
return mVendorId;
|
||||
return vendorId_;
|
||||
}
|
||||
|
||||
int32_t GetProductId() const
|
||||
{
|
||||
return mProductId;
|
||||
return productId_;
|
||||
}
|
||||
|
||||
int32_t GetClass() const
|
||||
{
|
||||
return mClass;
|
||||
return klass_;
|
||||
}
|
||||
|
||||
int32_t GetSubclass() const
|
||||
{
|
||||
return mSubclass;
|
||||
return subClass_;
|
||||
}
|
||||
|
||||
int32_t GetProtocol() const
|
||||
{
|
||||
return mProtocol;
|
||||
return protocol_;
|
||||
}
|
||||
|
||||
int32_t GetConfigCount() const
|
||||
{
|
||||
return configs.size();
|
||||
return configs_.size();
|
||||
}
|
||||
|
||||
int32_t GetConfig(uint32_t index, USBConfig &config) const
|
||||
{
|
||||
if (index >= configs.size()) {
|
||||
if (index >= configs_.size()) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
config = configs[index];
|
||||
config = configs_[index];
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void SetConfigs(const std::vector<USBConfig> &configs)
|
||||
{
|
||||
this->configs = configs;
|
||||
this->configs_ = configs;
|
||||
}
|
||||
|
||||
uint8_t GetDevAddr() const
|
||||
{
|
||||
return devAddr;
|
||||
}
|
||||
uint8_t GetBusNum() const
|
||||
{
|
||||
return busNum;
|
||||
}
|
||||
bool GetDescConfigCount()
|
||||
{
|
||||
return descConfigCount;
|
||||
return devAddr_;
|
||||
}
|
||||
|
||||
void SetDevAddr(uint8_t Num)
|
||||
uint8_t GetBusNum() const
|
||||
{
|
||||
devAddr = Num;
|
||||
return busNum_;
|
||||
}
|
||||
void SetBusNum(uint8_t Num)
|
||||
|
||||
bool GetDescConfigCount()
|
||||
{
|
||||
busNum = Num;
|
||||
return descConfigCount_;
|
||||
}
|
||||
void SetName(const std::string &Name)
|
||||
|
||||
void SetDevAddr(uint8_t addr)
|
||||
{
|
||||
mName = Name;
|
||||
devAddr_ = addr;
|
||||
}
|
||||
void SetManufacturerName(const std::string &Name)
|
||||
|
||||
void SetBusNum(uint8_t num)
|
||||
{
|
||||
mManufacturerName = Name;
|
||||
busNum_ = num;
|
||||
}
|
||||
void SetProductName(const std::string &Name)
|
||||
|
||||
void SetName(const std::string &name)
|
||||
{
|
||||
mProductName = Name;
|
||||
name_ = name;
|
||||
}
|
||||
void SetVersion(const std::string &Name)
|
||||
|
||||
void SetManufacturerName(const std::string &manufacturerName)
|
||||
{
|
||||
mVersion = Name;
|
||||
manufacturerName_ = manufacturerName;
|
||||
}
|
||||
void SetVendorId(int Id)
|
||||
|
||||
void SetProductName(const std::string &productName)
|
||||
{
|
||||
mVendorId = Id;
|
||||
productName_ = productName;
|
||||
}
|
||||
void SetProductId(int Id)
|
||||
|
||||
void SetVersion(const std::string &version)
|
||||
{
|
||||
mProductId = Id;
|
||||
version_ = version;
|
||||
}
|
||||
void SetClass(int Id)
|
||||
|
||||
void SetVendorId(int32_t vendorId)
|
||||
{
|
||||
mClass = Id;
|
||||
vendorId_ = vendorId;
|
||||
}
|
||||
void SetSubclass(int Id)
|
||||
|
||||
void SetProductId(int32_t productId)
|
||||
{
|
||||
mSubclass = Id;
|
||||
productId_ = productId;
|
||||
}
|
||||
void SetProtocol(int Id)
|
||||
|
||||
void SetClass(int32_t deviceClass)
|
||||
{
|
||||
mProtocol = Id;
|
||||
klass_ = deviceClass;
|
||||
}
|
||||
|
||||
void SetSubclass(int32_t subClass)
|
||||
{
|
||||
subClass_ = subClass;
|
||||
}
|
||||
|
||||
void SetProtocol(int32_t protocol)
|
||||
{
|
||||
protocol_ = protocol;
|
||||
}
|
||||
|
||||
void SetDescConfigCount(uint8_t count)
|
||||
{
|
||||
descConfigCount = count;
|
||||
descConfigCount_ = count;
|
||||
}
|
||||
|
||||
std::vector<USBConfig> &GetConfigs()
|
||||
{
|
||||
return configs;
|
||||
return configs_;
|
||||
}
|
||||
|
||||
std::string ToString() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "mName=" << mName << ","
|
||||
<< "mManufacturerName=" << mManufacturerName << ","
|
||||
<< "mProductName=" << mProductName << ","
|
||||
<< "mVersion=" << mVersion << ","
|
||||
<< "mSerial=" << mSerial << ","
|
||||
<< "busNum=" << (int32_t)busNum << ","
|
||||
<< "devAddr=" << (int32_t)devAddr << ","
|
||||
<< "mVendorId=" << mVendorId << ","
|
||||
<< "mProductId=" << mProductId << ","
|
||||
<< "mClass=" << mClass << ","
|
||||
<< "mSubclass=" << mSubclass << ","
|
||||
<< "mProtocol=" << mProtocol << "";
|
||||
ss << "name_=" << name_ << ","
|
||||
<< "manufacturerName_=" << manufacturerName_ << ","
|
||||
<< "productName_=" << productName_ << ","
|
||||
<< "version_=" << version_ << ","
|
||||
<< "serial_=" << serial_ << ","
|
||||
<< "busNum_=" << (int32_t)busNum_ << ","
|
||||
<< "devAddr_=" << (int32_t)devAddr_ << ","
|
||||
<< "vendorId_=" << vendorId_ << ","
|
||||
<< "productId_=" << productId_ << ","
|
||||
<< "klass_=" << klass_ << ","
|
||||
<< "subClass_=" << subClass_ << ","
|
||||
<< "protocol_=" << protocol_ << "";
|
||||
std::string str = "UsbDevice[" + ss.str() + "]; ";
|
||||
ss.str("");
|
||||
std::string strConfigs;
|
||||
for (size_t i = 0; i < configs.size(); ++i) {
|
||||
const USBConfig &config = configs[i];
|
||||
for (size_t i = 0; i < configs_.size(); ++i) {
|
||||
const USBConfig &config = configs_[i];
|
||||
strConfigs += config.ToString();
|
||||
}
|
||||
str += strConfigs;
|
||||
return str;
|
||||
}
|
||||
|
||||
void SetiManufacturer(uint8_t idx)
|
||||
void SetiManufacturer(uint8_t manufacturer)
|
||||
{
|
||||
this->iManufacturer = idx;
|
||||
this->iManufacturer_ = manufacturer;
|
||||
}
|
||||
|
||||
uint8_t GetiManufacturer()
|
||||
{
|
||||
return this->iManufacturer;
|
||||
return this->iManufacturer_;
|
||||
}
|
||||
void SetiProduct(uint8_t idx)
|
||||
|
||||
void SetiProduct(uint8_t product)
|
||||
{
|
||||
this->iProduct = idx;
|
||||
this->iProduct_ = product;
|
||||
}
|
||||
|
||||
uint8_t GetiProduct()
|
||||
{
|
||||
return this->iProduct;
|
||||
return this->iProduct_;
|
||||
}
|
||||
void SetiSerialNumber(uint8_t idx)
|
||||
|
||||
void SetiSerialNumber(uint8_t sn)
|
||||
{
|
||||
this->iSerialNumber = idx;
|
||||
this->iSerialNumber_ = sn;
|
||||
}
|
||||
|
||||
uint8_t GetiSerialNumber()
|
||||
{
|
||||
return this->iSerialNumber;
|
||||
return this->iSerialNumber_;
|
||||
}
|
||||
void SetmSerial(std::string Name)
|
||||
|
||||
void SetmSerial(std::string serial)
|
||||
{
|
||||
this->mSerial = Name;
|
||||
this->serial_ = serial;
|
||||
}
|
||||
|
||||
const std::string GetmSerial() const
|
||||
{
|
||||
return this->mSerial;
|
||||
return this->serial_;
|
||||
}
|
||||
void SetbMaxPacketSize0(uint8_t val)
|
||||
|
||||
void SetbMaxPacketSize0(uint8_t maxSize)
|
||||
{
|
||||
this->bMaxPacketSize0 = val;
|
||||
this->bMaxPacketSize0_ = maxSize;
|
||||
}
|
||||
|
||||
uint8_t GetbMaxPacketSize0()
|
||||
{
|
||||
return this->bMaxPacketSize0;
|
||||
return this->bMaxPacketSize0_;
|
||||
}
|
||||
void SetbcdUSB(uint16_t val)
|
||||
|
||||
void SetbcdUSB(uint16_t bcdUSB)
|
||||
{
|
||||
this->bcdUSB = val;
|
||||
this->bcdUSB_ = bcdUSB;
|
||||
}
|
||||
|
||||
uint16_t GetbcdUSB()
|
||||
{
|
||||
return this->bcdUSB;
|
||||
return this->bcdUSB_;
|
||||
}
|
||||
void SetbcdDevice(uint16_t val)
|
||||
|
||||
void SetbcdDevice(uint16_t bcdDevice)
|
||||
{
|
||||
this->bcdDevice = val;
|
||||
this->bcdDevice_ = bcdDevice;
|
||||
}
|
||||
|
||||
uint16_t GetbcdDevice()
|
||||
{
|
||||
return this->bcdDevice;
|
||||
return this->bcdDevice_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mManufacturerName;
|
||||
std::string mProductName;
|
||||
std::string mVersion;
|
||||
std::string mSerial;
|
||||
uint8_t devAddr;
|
||||
uint8_t busNum;
|
||||
uint8_t descConfigCount = UINT8_MAX;
|
||||
std::string name_;
|
||||
std::string manufacturerName_;
|
||||
std::string productName_;
|
||||
std::string version_;
|
||||
std::string serial_;
|
||||
uint8_t devAddr_;
|
||||
uint8_t busNum_;
|
||||
uint8_t descConfigCount_ = UINT8_MAX;
|
||||
|
||||
uint8_t bMaxPacketSize0 = UINT8_MAX;
|
||||
uint16_t bcdUSB = UINT16_MAX;
|
||||
uint16_t bcdDevice = UINT16_MAX;
|
||||
uint8_t iManufacturer = UINT8_MAX;
|
||||
uint8_t iProduct = UINT8_MAX;
|
||||
uint8_t iSerialNumber = UINT8_MAX;
|
||||
uint8_t bMaxPacketSize0_ = UINT8_MAX;
|
||||
uint16_t bcdUSB_ = UINT16_MAX;
|
||||
uint16_t bcdDevice_ = UINT16_MAX;
|
||||
uint8_t iManufacturer_ = UINT8_MAX;
|
||||
uint8_t iProduct_ = UINT8_MAX;
|
||||
uint8_t iSerialNumber_ = UINT8_MAX;
|
||||
|
||||
int mVendorId;
|
||||
int mProductId;
|
||||
int mClass;
|
||||
int mSubclass;
|
||||
int mProtocol;
|
||||
std::vector<USBConfig> configs;
|
||||
int32_t vendorId_;
|
||||
int32_t productId_;
|
||||
int32_t klass_;
|
||||
int32_t subClass_;
|
||||
int32_t protocol_;
|
||||
std::vector<USBConfig> configs_;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -40,8 +40,8 @@ public:
|
||||
uint8_t GetDevAddr() const;
|
||||
|
||||
private:
|
||||
uint8_t busNum;
|
||||
uint8_t devAddr;
|
||||
uint8_t busNum_;
|
||||
uint8_t devAddr_;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -27,103 +27,109 @@ class USBEndpoint {
|
||||
public:
|
||||
USBEndpoint(uint32_t address, uint32_t attributes, uint32_t interval, uint32_t maxPacketSize)
|
||||
{
|
||||
this->address = address;
|
||||
this->attributes = attributes;
|
||||
this->interval = interval;
|
||||
this->maxPacketSize = maxPacketSize;
|
||||
this->address_ = address;
|
||||
this->attributes_ = attributes;
|
||||
this->interval_ = interval;
|
||||
this->maxPacketSize_ = maxPacketSize;
|
||||
}
|
||||
USBEndpoint() {}
|
||||
~USBEndpoint() {}
|
||||
|
||||
uint8_t GetNumber() const
|
||||
{
|
||||
return address & USB_ENDPOINT_NUMBER_MASK;
|
||||
return address_ & USB_ENDPOINT_NUMBER_MASK;
|
||||
}
|
||||
const int32_t &GetAddress() const
|
||||
{
|
||||
return address;
|
||||
return address_;
|
||||
}
|
||||
|
||||
int32_t GetDirection() const
|
||||
{
|
||||
return address & USB_ENDPOINT_DIR_MASK;
|
||||
return address_ & USB_ENDPOINT_DIR_MASK;
|
||||
}
|
||||
|
||||
const int32_t &GetAttributes() const
|
||||
{
|
||||
return attributes;
|
||||
return attributes_;
|
||||
}
|
||||
|
||||
int32_t GetEndpointNumber() const
|
||||
{
|
||||
return address & USB_ENDPOINT_NUMBER_MASK;
|
||||
return address_ & USB_ENDPOINT_NUMBER_MASK;
|
||||
}
|
||||
|
||||
const int32_t &GetInterval() const
|
||||
{
|
||||
return interval;
|
||||
return interval_;
|
||||
}
|
||||
|
||||
const int32_t &GetMaxPacketSize() const
|
||||
{
|
||||
return maxPacketSize;
|
||||
return maxPacketSize_;
|
||||
}
|
||||
|
||||
int32_t GetType() const
|
||||
{
|
||||
return (attributes & USB_ENDPOINT_XFERTYPE_MASK);
|
||||
return (attributes_ & USB_ENDPOINT_XFERTYPE_MASK);
|
||||
}
|
||||
|
||||
std::string ToString() const
|
||||
{
|
||||
std::string ret = "USBEndpoint:[Address:";
|
||||
ret.append(std::to_string(address))
|
||||
ret.append(std::to_string(address_))
|
||||
.append(", Direction:")
|
||||
.append(std::to_string(GetDirection()))
|
||||
.append(", Attributes:")
|
||||
.append(std::to_string(attributes))
|
||||
.append(std::to_string(attributes_))
|
||||
.append(", EndpointNumber:")
|
||||
.append(std::to_string(GetEndpointNumber()))
|
||||
.append(", Interval:")
|
||||
.append(std::to_string(interval))
|
||||
.append(std::to_string(interval_))
|
||||
.append(", MaxPacketSize:")
|
||||
.append(std::to_string(maxPacketSize))
|
||||
.append(std::to_string(maxPacketSize_))
|
||||
.append(", Type:")
|
||||
.append(std::to_string(GetType()))
|
||||
.append("]");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SetAddr(int32_t val)
|
||||
{
|
||||
address = val;
|
||||
address_ = val;
|
||||
}
|
||||
|
||||
void SetAttr(int32_t val)
|
||||
{
|
||||
attributes = val;
|
||||
attributes_ = val;
|
||||
}
|
||||
|
||||
void SetInterval(int32_t val)
|
||||
{
|
||||
interval = val;
|
||||
interval_ = val;
|
||||
}
|
||||
|
||||
void SetMaxPacketSize(int32_t val)
|
||||
{
|
||||
maxPacketSize = val;
|
||||
maxPacketSize_ = val;
|
||||
}
|
||||
|
||||
void SetInterfaceId(uint8_t interfaceId)
|
||||
{
|
||||
this->interfaceId = interfaceId;
|
||||
this->interfaceId_ = interfaceId;
|
||||
}
|
||||
|
||||
int8_t GetInterfaceId() const
|
||||
{
|
||||
return interfaceId;
|
||||
return interfaceId_;
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t address = INVALID_USB_INT_VALUE;
|
||||
int32_t attributes = INVALID_USB_INT_VALUE;
|
||||
int32_t interval = INVALID_USB_INT_VALUE;
|
||||
int32_t maxPacketSize = INVALID_USB_INT_VALUE;
|
||||
uint8_t interfaceId = UINT8_MAX;
|
||||
int32_t address_ = INVALID_USB_INT_VALUE;
|
||||
int32_t attributes_ = INVALID_USB_INT_VALUE;
|
||||
int32_t interval_ = INVALID_USB_INT_VALUE;
|
||||
int32_t maxPacketSize_ = INVALID_USB_INT_VALUE;
|
||||
uint8_t interfaceId_ = UINT8_MAX;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -20,110 +20,114 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "usb_endpoint.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
class UsbInterface {
|
||||
public:
|
||||
UsbInterface(int32_t mId,
|
||||
int32_t mProtocol,
|
||||
int32_t mClass,
|
||||
int32_t mSubClass,
|
||||
int32_t mAlternateSetting,
|
||||
std::string mName,
|
||||
std::vector<USBEndpoint> mEndpoints)
|
||||
UsbInterface(int32_t id,
|
||||
int32_t protocol,
|
||||
int32_t interfaceClass,
|
||||
int32_t subClass,
|
||||
int32_t alternateSetting,
|
||||
std::string name,
|
||||
std::vector<USBEndpoint> endpoints)
|
||||
{
|
||||
this->mId = mId;
|
||||
this->mProtocol = mProtocol;
|
||||
this->mClass = mClass;
|
||||
this->mSubClass = mSubClass;
|
||||
this->mAlternateSetting = mAlternateSetting;
|
||||
this->mEndpoints = mEndpoints;
|
||||
this->id_ = id;
|
||||
this->protocol_ = protocol;
|
||||
this->klass_ = interfaceClass;
|
||||
this->subClass_ = subClass;
|
||||
this->alternateSetting_ = alternateSetting;
|
||||
this->endpoints_ = endpoints;
|
||||
}
|
||||
|
||||
UsbInterface() {}
|
||||
|
||||
const std::string &GetName() const
|
||||
{
|
||||
return mName;
|
||||
return name_;
|
||||
}
|
||||
|
||||
int32_t GetId() const
|
||||
{
|
||||
return mId;
|
||||
return id_;
|
||||
}
|
||||
|
||||
int32_t GetClass() const
|
||||
{
|
||||
return mClass;
|
||||
return klass_;
|
||||
}
|
||||
|
||||
int32_t GetSubClass() const
|
||||
{
|
||||
return mSubClass;
|
||||
return subClass_;
|
||||
}
|
||||
|
||||
int32_t GetAlternateSetting() const
|
||||
{
|
||||
return mAlternateSetting;
|
||||
return alternateSetting_;
|
||||
}
|
||||
|
||||
int32_t GetProtocol() const
|
||||
{
|
||||
return mProtocol;
|
||||
return protocol_;
|
||||
}
|
||||
|
||||
int32_t GetEndpointCount() const
|
||||
{
|
||||
return mEndpoints.size();
|
||||
return endpoints_.size();
|
||||
}
|
||||
|
||||
void GetEndpoint(uint32_t index, USBEndpoint &ep) const
|
||||
std::optional<USBEndpoint> GetEndpoint(uint32_t index) const
|
||||
{
|
||||
if (index < mEndpoints.size()) {
|
||||
ep = mEndpoints[index];
|
||||
if (index >= endpoints_.size()) {
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "invalid index=%{public}u !", index);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return endpoints_[index];
|
||||
}
|
||||
|
||||
std::vector<USBEndpoint> &GetEndpoints()
|
||||
{
|
||||
return mEndpoints;
|
||||
return endpoints_;
|
||||
}
|
||||
|
||||
void SetEndpoints(const std::vector<USBEndpoint> &eps)
|
||||
{
|
||||
mEndpoints = eps;
|
||||
endpoints_ = eps;
|
||||
}
|
||||
|
||||
void SetId(int Val)
|
||||
void SetId(int32_t id)
|
||||
{
|
||||
mId = Val;
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
void SetProtocol(int Val)
|
||||
void SetProtocol(int32_t protocol)
|
||||
{
|
||||
mProtocol = Val;
|
||||
protocol_ = protocol;
|
||||
}
|
||||
|
||||
void SetClass(int Val)
|
||||
void SetClass(int32_t klass)
|
||||
{
|
||||
mClass = Val;
|
||||
klass_ = klass;
|
||||
}
|
||||
|
||||
void SetSubClass(int Val)
|
||||
void SetSubClass(int32_t subClass)
|
||||
{
|
||||
mSubClass = Val;
|
||||
subClass_ = subClass;
|
||||
}
|
||||
|
||||
void SetAlternateSetting(int Val)
|
||||
void SetAlternateSetting(int32_t alternateSetting)
|
||||
{
|
||||
mAlternateSetting = Val;
|
||||
alternateSetting_ = alternateSetting;
|
||||
}
|
||||
|
||||
void SetName(const std::string &Name)
|
||||
void SetName(const std::string &name)
|
||||
{
|
||||
mName = Name;
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
~UsbInterface() {}
|
||||
@ -131,17 +135,17 @@ public:
|
||||
std::string ToString() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "id=" << mId << ","
|
||||
<< "mName=" << mName << ","
|
||||
<< "iInterface=" << (int32_t)iInterface << ","
|
||||
<< "mClass=" << mClass << ","
|
||||
<< "mSubClass=" << mSubClass << ","
|
||||
<< "mProtocol=" << mProtocol << ","
|
||||
<< "mAlternateSetting=" << mAlternateSetting << "";
|
||||
ss << "id=" << id_ << ","
|
||||
<< "name_=" << name_ << ","
|
||||
<< "iInterface_=" << (int32_t)iInterface_ << ","
|
||||
<< "klass_=" << klass_ << ","
|
||||
<< "subClass_=" << subClass_ << ","
|
||||
<< "protocol_=" << protocol_ << ","
|
||||
<< "alternateSetting_=" << alternateSetting_ << "";
|
||||
std::string str = "UsbInterface[" + ss.str() + "]; ";
|
||||
ss.str("");
|
||||
for (size_t i = 0; i < mEndpoints.size(); ++i) {
|
||||
const USBEndpoint &endpoint = mEndpoints[i];
|
||||
for (size_t i = 0; i < endpoints_.size(); ++i) {
|
||||
const USBEndpoint &endpoint = endpoints_[i];
|
||||
str += endpoint.ToString();
|
||||
}
|
||||
return str;
|
||||
@ -149,23 +153,23 @@ public:
|
||||
|
||||
void SetiInterface(uint8_t idx)
|
||||
{
|
||||
this->iInterface = idx;
|
||||
this->iInterface_ = idx;
|
||||
}
|
||||
|
||||
uint8_t GetiInterface()
|
||||
{
|
||||
return this->iInterface;
|
||||
return this->iInterface_;
|
||||
}
|
||||
|
||||
private:
|
||||
int mId;
|
||||
int mProtocol;
|
||||
int mClass;
|
||||
int mSubClass;
|
||||
int mAlternateSetting;
|
||||
std::string mName;
|
||||
std::vector<USBEndpoint> mEndpoints;
|
||||
uint8_t iInterface = UINT8_MAX;
|
||||
int32_t id_ = INT32_MAX;
|
||||
int32_t protocol_ = INT32_MAX;
|
||||
int32_t klass_ = INT32_MAX;
|
||||
int32_t subClass_ = INT32_MAX;
|
||||
int32_t alternateSetting_ = INT32_MAX;
|
||||
std::string name_;
|
||||
std::vector<USBEndpoint> endpoints_;
|
||||
uint8_t iInterface_ = UINT8_MAX;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -32,42 +32,42 @@ public:
|
||||
int32_t Abort();
|
||||
void SetPipe(const USBDevicePipe &pipe)
|
||||
{
|
||||
this->pipe = pipe;
|
||||
this->pipe_ = pipe;
|
||||
}
|
||||
void SetEndpoint(const USBEndpoint &endpoint)
|
||||
{
|
||||
this->endpoint = endpoint;
|
||||
this->endpoint_ = endpoint;
|
||||
}
|
||||
void SetClientData(std::vector<uint8_t> bufferData)
|
||||
{
|
||||
clientData = bufferData;
|
||||
clientData_ = bufferData;
|
||||
}
|
||||
void SetReqData(std::vector<uint8_t> bufferData)
|
||||
{
|
||||
reqData = bufferData;
|
||||
reqData_ = bufferData;
|
||||
}
|
||||
std::vector<uint8_t> &GetClientData()
|
||||
{
|
||||
return clientData;
|
||||
return clientData_;
|
||||
}
|
||||
std::vector<uint8_t> &GetReqData()
|
||||
{
|
||||
return reqData;
|
||||
return reqData_;
|
||||
}
|
||||
const USBDevicePipe &GetPipe() const
|
||||
{
|
||||
return pipe;
|
||||
return pipe_;
|
||||
}
|
||||
const USBEndpoint &GetEndpoint() const
|
||||
{
|
||||
return endpoint;
|
||||
return endpoint_;
|
||||
}
|
||||
|
||||
public:
|
||||
USBDevicePipe pipe;
|
||||
USBEndpoint endpoint;
|
||||
std::vector<uint8_t> clientData;
|
||||
std::vector<uint8_t> reqData;
|
||||
private:
|
||||
USBDevicePipe pipe_;
|
||||
USBEndpoint endpoint_;
|
||||
std::vector<uint8_t> clientData_;
|
||||
std::vector<uint8_t> reqData_;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
DISALLOW_COPY_AND_MOVE(UsbSrvClient);
|
||||
|
||||
int32_t OpenDevice(const UsbDevice &device, USBDevicePipe &pip);
|
||||
int32_t HasRight(std::string deviceName);
|
||||
bool HasRight(std::string deviceName);
|
||||
int32_t RequestRight(std::string deviceName);
|
||||
int32_t RemoveRight(std::string deviceName);
|
||||
int32_t GetDevices(std::vector<UsbDevice> &deviceList);
|
||||
@ -74,6 +74,7 @@ public:
|
||||
{
|
||||
return SEVVERSION;
|
||||
}
|
||||
|
||||
int32_t RegBulkCallback(USBDevicePipe &pip, const USBEndpoint &endpoint, const sptr<IRemoteObject> &cb);
|
||||
int32_t UnRegBulkCallback(USBDevicePipe &pip, const USBEndpoint &endpoint);
|
||||
int32_t BulkRead(USBDevicePipe &pip, const USBEndpoint &endpoint, sptr<Ashmem> &ashmem);
|
||||
|
@ -25,7 +25,7 @@ namespace OHOS {
|
||||
namespace USB {
|
||||
USBDevicePipe::USBDevicePipe() {}
|
||||
USBDevicePipe::USBDevicePipe(uint8_t busNum, uint8_t devAddr)
|
||||
: busNum(busNum), devAddr(devAddr)
|
||||
: busNum_(busNum), devAddr_(devAddr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -71,22 +71,22 @@ int32_t USBDevicePipe::SetInterface(const UsbInterface &interface)
|
||||
|
||||
void USBDevicePipe::SetBusNum(uint8_t busNum)
|
||||
{
|
||||
this->busNum = busNum;
|
||||
this->busNum_ = busNum;
|
||||
}
|
||||
|
||||
void USBDevicePipe::SetDevAddr(uint8_t devAddr)
|
||||
{
|
||||
this->devAddr = devAddr;
|
||||
this->devAddr_ = devAddr;
|
||||
}
|
||||
|
||||
uint8_t USBDevicePipe::GetBusNum() const
|
||||
{
|
||||
return busNum;
|
||||
return busNum_;
|
||||
}
|
||||
|
||||
uint8_t USBDevicePipe::GetDevAddr() const
|
||||
{
|
||||
return devAddr;
|
||||
return devAddr_;
|
||||
}
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
|
@ -21,8 +21,8 @@ namespace OHOS {
|
||||
namespace USB {
|
||||
int32_t UsbRequest::Initialize(const USBDevicePipe &pipe, const USBEndpoint &endpoint)
|
||||
{
|
||||
this->pipe = pipe;
|
||||
this->endpoint = endpoint;
|
||||
this->pipe_ = pipe;
|
||||
this->endpoint_ = endpoint;
|
||||
int32_t ret = UsbSrvClient::GetInstance().RequestInitialize(*this);
|
||||
if (ERR_OK != ret) {
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "UsbRequest::%{public}s:%{public}d failed with ret = %{public}d.", __func__,
|
||||
|
@ -91,15 +91,11 @@ int32_t UsbSrvClient::OpenDevice(const UsbDevice &device, USBDevicePipe &pipe)
|
||||
return UEC_OK;
|
||||
}
|
||||
|
||||
int32_t UsbSrvClient::HasRight(std::string deviceName)
|
||||
bool UsbSrvClient::HasRight(std::string deviceName)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_INNERKIT, " Calling HasRight Start!");
|
||||
RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
|
||||
int32_t ret = proxy_->HasRight(deviceName);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, " Calling HasRight False!");
|
||||
}
|
||||
return ret;
|
||||
RETURN_IF_WITH_RET(Connect() != UEC_OK, false);
|
||||
return proxy_->HasRight(deviceName);
|
||||
}
|
||||
|
||||
int32_t UsbSrvClient::RequestRight(std::string deviceName)
|
||||
|
@ -13,58 +13,56 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "usbd_bulk_callback.h"
|
||||
#include <hdf_base.h>
|
||||
#include <hdf_log.h>
|
||||
#include <hdf_sbuf_ipc.h>
|
||||
#include "usb_errors.h"
|
||||
|
||||
#define HDF_LOG_TAG USBD_BULK_CALLBACK
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS::USB {
|
||||
int32_t UsbdBulkCallBack::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
HDF_LOGI("%{public}s:%{public}d OnRemoteRequest entry! code:%{public}d", __func__, __LINE__, code);
|
||||
switch (code) {
|
||||
case CMD_USBD_BULK_CALLBACK_WRITE: {
|
||||
if (data.ReadInterfaceToken() != GetObjectDescriptor()) {
|
||||
HDF_LOGE("%{public}s: checkout interface descriptor failed!", __func__);
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "%{public}s: checkout interface descriptor failed!", __func__);
|
||||
return UEC_SERVICE_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
int32_t status;
|
||||
int32_t actLength;
|
||||
if (!data.ReadInt32(status)) {
|
||||
HDF_LOGE("%{public}s:%{public}d get status error", __func__, __LINE__);
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "%{public}s:%{public}d get status error", __func__, __LINE__);
|
||||
return UEC_SERVICE_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadInt32(actLength)) {
|
||||
HDF_LOGE("%{public}s:%{public}d get actLength error", __func__, __LINE__);
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "%{public}s:%{public}d get actLength error", __func__, __LINE__);
|
||||
return UEC_SERVICE_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
HDF_LOGI("%{public}s:%{public}d status:%{public}d actLength:%{public}d", __func__, __LINE__, status,
|
||||
actLength);
|
||||
|
||||
USB_HILOGI(MODULE_USB_INNERKIT, "%{public}s:%{public}d status:%{public}d actLength:%{public}d", __func__,
|
||||
__LINE__, status, actLength);
|
||||
OnBulkWriteCallback(status, actLength);
|
||||
break;
|
||||
}
|
||||
case CMD_USBD_BULK_CALLBACK_READ: {
|
||||
if (data.ReadInterfaceToken() != GetObjectDescriptor()) {
|
||||
HDF_LOGE("%{public}s: checkout interface descriptor failed!", __func__);
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "%{public}s: checkout interface descriptor failed!", __func__);
|
||||
return UEC_SERVICE_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
int32_t status;
|
||||
int32_t actLength;
|
||||
if (!data.ReadInt32(status)) {
|
||||
HDF_LOGE("%{public}s:%{public}d get status error", __func__, __LINE__);
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "%{public}s:%{public}d get status error", __func__, __LINE__);
|
||||
return UEC_SERVICE_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadInt32(actLength)) {
|
||||
HDF_LOGE("%{public}s:%{public}d get actLength error", __func__, __LINE__);
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "%{public}s:%{public}d get actLength error", __func__, __LINE__);
|
||||
return UEC_SERVICE_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
HDF_LOGI("%{public}s:%{public}d status:%{public}d actLength:%{public}d", __func__, __LINE__, status,
|
||||
actLength);
|
||||
|
||||
USB_HILOGI(MODULE_USB_INNERKIT, "%{public}s:%{public}d status:%{public}d actLength:%{public}d", __func__,
|
||||
__LINE__, status, actLength);
|
||||
OnBulkReadCallback(status, actLength);
|
||||
break;
|
||||
}
|
||||
|
@ -90,22 +90,18 @@ struct USBControlTransferAsyncContext : USBAsyncContext {
|
||||
int32_t index;
|
||||
uint8_t *buffer;
|
||||
uint32_t bufferLength;
|
||||
uint32_t dataSize;
|
||||
int32_t timeOut = 0;
|
||||
};
|
||||
|
||||
struct USBBulkTransferAsyncContext : USBAsyncContext {
|
||||
uint8_t *buffer;
|
||||
uint32_t bufferLength;
|
||||
uint32_t dataSize;
|
||||
int32_t timeOut = 0;
|
||||
USBDevicePipe pipe;
|
||||
USBEndpoint endpoint;
|
||||
};
|
||||
|
||||
struct USBQueueAsyncContext : USBAsyncContext {
|
||||
UsbRequest req;
|
||||
uint8_t *buffer;
|
||||
uint32_t bufferLength;
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
#endif // USB_ASYNC_CONTEXT_H
|
||||
|
@ -32,10 +32,6 @@ void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, con
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> buf = std::make_unique<char[]>(bufLen);
|
||||
if (buf.get() == nullptr) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s nullptr js object to string malloc failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
errno_t ret = memset_s(buf.get(), bufLen, 0, bufLen);
|
||||
NAPI_ASSERT_RETURN_VOID(env, ret == EOK, "JsValueToString memset_s failed.");
|
||||
@ -48,8 +44,10 @@ void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, con
|
||||
void NapiUtil::JsObjectToString(const napi_env &env, const napi_value &object, std::string fieldStr,
|
||||
const int32_t bufLen, std::string &fieldRef)
|
||||
{
|
||||
if (bufLen <= 0)
|
||||
if (bufLen <= 0) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "invalid bufLen=%{public}d", bufLen);
|
||||
return;
|
||||
}
|
||||
|
||||
bool hasProperty = false;
|
||||
napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty);
|
||||
@ -61,10 +59,6 @@ void NapiUtil::JsObjectToString(const napi_env &env, const napi_value &object, s
|
||||
napi_typeof(env, field, &valueType);
|
||||
NAPI_ASSERT_RETURN_VOID(env, valueType == napi_string, "Wrong argument type. String expected.");
|
||||
std::unique_ptr<char[]> buf = std::make_unique<char[]>(bufLen);
|
||||
if (buf == nullptr) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s nullptr js object to string malloc failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
errno_t ret = memset_s(buf.get(), bufLen, 0, bufLen);
|
||||
NAPI_ASSERT_RETURN_VOID(env, ret == EOK, "JsObjectToString memset_s failed.");
|
||||
|
@ -100,14 +100,19 @@ static void CtoJSUsbInterface(const napi_env &env, napi_value &obj, const UsbInt
|
||||
NapiUtil::SetValueInt32(env, "subclass", usbInterface.GetSubClass(), obj);
|
||||
NapiUtil::SetValueInt32(env, "alternateSetting", usbInterface.GetAlternateSetting(), obj);
|
||||
NapiUtil::SetValueUtf8String(env, "name", usbInterface.GetName(), obj);
|
||||
|
||||
napi_value arr;
|
||||
napi_create_array(env, &arr);
|
||||
for (int32_t i = 0; i < usbInterface.GetEndpointCount(); ++i) {
|
||||
USBEndpoint usbEndpoint;
|
||||
usbInterface.GetEndpoint(i, usbEndpoint);
|
||||
napi_value obj;
|
||||
CtoJSUsbEndpoint(env, obj, usbEndpoint);
|
||||
napi_set_element(env, arr, i, obj);
|
||||
auto usbEndpoint = usbInterface.GetEndpoint(i);
|
||||
if (!usbEndpoint.has_value()) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "GetEndpoint failed i=%{public}d", i);
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value objTmp;
|
||||
CtoJSUsbEndpoint(env, objTmp, usbEndpoint.value());
|
||||
napi_set_element(env, arr, i, objTmp);
|
||||
}
|
||||
napi_set_named_property(env, obj, "endpoints", arr);
|
||||
}
|
||||
@ -123,12 +128,12 @@ static void CtoJSUsbConfig(const napi_env &env, napi_value &obj, const USBConfig
|
||||
NapiUtil::SetValueUtf8String(env, "name", usbConfig.GetName(), obj);
|
||||
napi_value arr;
|
||||
napi_create_array(env, &arr);
|
||||
for (int32_t i = 0; i < usbConfig.GetInterfaceCount(); ++i) {
|
||||
for (uint32_t i = 0; i < usbConfig.GetInterfaceCount(); ++i) {
|
||||
UsbInterface usbInterface;
|
||||
usbConfig.GetInterface(i, usbInterface);
|
||||
napi_value obj;
|
||||
CtoJSUsbInterface(env, obj, usbInterface);
|
||||
napi_set_element(env, arr, i, obj);
|
||||
napi_value objTmp;
|
||||
CtoJSUsbInterface(env, objTmp, usbInterface);
|
||||
napi_set_element(env, arr, i, objTmp);
|
||||
}
|
||||
napi_set_named_property(env, obj, "interfaces", arr);
|
||||
}
|
||||
@ -153,9 +158,9 @@ static void CtoJSUsbDevice(const napi_env &env, napi_value &obj, const UsbDevice
|
||||
for (int32_t i = 0; i < usbDevice.GetConfigCount(); ++i) {
|
||||
USBConfig usbConfig;
|
||||
usbDevice.GetConfig(i, usbConfig);
|
||||
napi_value obj;
|
||||
CtoJSUsbConfig(env, obj, usbConfig);
|
||||
napi_set_element(env, arr, i, obj);
|
||||
napi_value objTmp;
|
||||
CtoJSUsbConfig(env, objTmp, usbConfig);
|
||||
napi_set_element(env, arr, i, objTmp);
|
||||
}
|
||||
napi_set_named_property(env, obj, "configs", arr);
|
||||
}
|
||||
@ -182,26 +187,32 @@ static void ParseEndpointObj(const napi_env env, const napi_value endpointObj, U
|
||||
|
||||
static bool ParseEndpointsObjs(const napi_env env, const napi_value interfaceObj, std::vector<USBEndpoint> &eps)
|
||||
{
|
||||
// Get the array.
|
||||
bool result = false;
|
||||
napi_status status = napi_is_array(env, interfaceObj, &result);
|
||||
if (result == false || status != napi_ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
napi_value endpointsObjs;
|
||||
bool isGetObjSuccess = NapiUtil::JsObjectGetProperty(env, interfaceObj, "endpoints", endpointsObjs);
|
||||
if (!isGetObjSuccess) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, get endpoints failed.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
napi_status status = napi_is_array(env, endpointsObjs, &result);
|
||||
if (!result || status != napi_ok) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, invalid endpoints.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t endpointCount = 0;
|
||||
status = napi_get_array_length(env, endpointsObjs, &endpointCount);
|
||||
if (status != napi_ok) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "get len failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t k = 0; k < endpointCount; ++k) {
|
||||
napi_value endpointObj;
|
||||
napi_status status = napi_get_element(env, endpointsObjs, k, &endpointObj);
|
||||
status = napi_get_element(env, endpointsObjs, k, &endpointObj);
|
||||
if (status != napi_ok) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, get endpoints element failed k=%u.", __func__, k);
|
||||
return false;
|
||||
}
|
||||
USBEndpoint ep;
|
||||
@ -266,35 +277,49 @@ static void ParseInterfaceObj(const napi_env env, const napi_value interfaceObj,
|
||||
std::string name;
|
||||
NapiUtil::JsObjectToString(env, interfaceObj, "name", DEFAULT_DESCRIPTION_SIZE, name);
|
||||
std::vector<USBEndpoint> eps;
|
||||
ParseEndpointsObjs(env, interfaceObj, eps);
|
||||
|
||||
bool ret = ParseEndpointsObjs(env, interfaceObj, eps);
|
||||
NAPI_ASSERT_RETURN_VOID(env, ret == true, "Parse endpointers error.");
|
||||
|
||||
interface = UsbInterface(id, protocol, clzz, subClass, alternateSetting, name, eps);
|
||||
}
|
||||
|
||||
static bool ParseInterfacesObjs(const napi_env env, const napi_value configObj, std::vector<UsbInterface> &interfaces)
|
||||
{
|
||||
bool result = false;
|
||||
napi_status status = napi_is_array(env, configObj, &result);
|
||||
if (result && status == napi_ok) {
|
||||
napi_value interfacesObjs;
|
||||
bool isGetObjSuccess = NapiUtil::JsObjectGetProperty(env, configObj, "interfaces", interfacesObjs);
|
||||
if (!isGetObjSuccess) {
|
||||
return false;
|
||||
}
|
||||
uint32_t interfaceCount = 0;
|
||||
status = napi_get_array_length(env, interfacesObjs, &interfaceCount);
|
||||
for (uint32_t i = 0; i < interfaceCount; ++i) {
|
||||
napi_value interfaceObj;
|
||||
napi_status status = napi_get_element(env, interfacesObjs, i, &interfaceObj);
|
||||
if (status != napi_ok) {
|
||||
return false;
|
||||
}
|
||||
UsbInterface interface;
|
||||
ParseInterfaceObj(env, interfaceObj, interface);
|
||||
interfaces.push_back(interface);
|
||||
}
|
||||
napi_value interfacesObjs;
|
||||
bool isGetObjSuccess = NapiUtil::JsObjectGetProperty(env, configObj, "interfaces", interfacesObjs);
|
||||
if (!isGetObjSuccess) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, get interfaces failed.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
bool result = false;
|
||||
napi_status status = napi_is_array(env, interfacesObjs, &result);
|
||||
if (!result || status != napi_ok) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, invalid param.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t interfaceCount = 0;
|
||||
status = napi_get_array_length(env, interfacesObjs, &interfaceCount);
|
||||
if (status != napi_ok) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, get len failed.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < interfaceCount; ++i) {
|
||||
napi_value interfaceObj;
|
||||
status = napi_get_element(env, interfacesObjs, i, &interfaceObj);
|
||||
if (status != napi_ok) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "%{public}s, get element failed,i=%{public}u.", __func__, i);
|
||||
return false;
|
||||
}
|
||||
UsbInterface interface;
|
||||
ParseInterfaceObj(env, interfaceObj, interface);
|
||||
interfaces.push_back(interface);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ParseConfigObj(const napi_env env, const napi_value configObj, USBConfig &config)
|
||||
@ -309,7 +334,9 @@ static void ParseConfigObj(const napi_env env, const napi_value configObj, USBCo
|
||||
NapiUtil::JsObjectToString(env, configObj, "name", DEFAULT_DESCRIPTION_SIZE, name);
|
||||
|
||||
std::vector<UsbInterface> interfaces;
|
||||
ParseInterfacesObjs(env, configObj, interfaces);
|
||||
bool ret = ParseInterfacesObjs(env, configObj, interfaces);
|
||||
NAPI_ASSERT_RETURN_VOID(env, ret == true, "Parse interfaces error.");
|
||||
|
||||
config = USBConfig(id, attributes, name, maxPower, interfaces);
|
||||
}
|
||||
|
||||
@ -376,7 +403,7 @@ static napi_value CoreGetDevices(napi_env env, napi_callback_info info)
|
||||
napi_value result;
|
||||
if (ret != UEC_OK) {
|
||||
napi_get_undefined(env, &result);
|
||||
USB_HILOGE(MODULE_JS_NAPI, "end call %{public}s, get device faild ret : %{public}d", __func__, ret);
|
||||
USB_HILOGE(MODULE_JS_NAPI, "end call %{public}s, get device failed ret : %{public}d", __func__, ret);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -435,11 +462,11 @@ static napi_value CoreHasRight(napi_env env, napi_callback_info info)
|
||||
std::string deviceName;
|
||||
NapiUtil::JsValueToString(env, args[INDEX_0], STR_DEFAULT_SIZE, deviceName);
|
||||
|
||||
int32_t result = g_usbClient.HasRight(deviceName);
|
||||
bool result = g_usbClient.HasRight(deviceName);
|
||||
USB_HILOGD(MODULE_JS_NAPI, "client called result %{public}d", result);
|
||||
|
||||
napi_value napiValue = nullptr;
|
||||
napi_get_boolean(env, result == UEC_OK, &napiValue);
|
||||
napi_get_boolean(env, result, &napiValue);
|
||||
|
||||
return napiValue;
|
||||
}
|
||||
@ -607,7 +634,7 @@ static napi_value CoreGetCurrentFunctions(napi_env env, napi_callback_info info)
|
||||
napi_value result;
|
||||
if (ret != UEC_OK) {
|
||||
napi_get_undefined(env, &result);
|
||||
USB_HILOGE(MODULE_JS_NAPI, "end call %{public}s, get ports faild ret : %{public}d", __func__, ret);
|
||||
USB_HILOGE(MODULE_JS_NAPI, "end call %{public}s, get ports failed ret : %{public}d", __func__, ret);
|
||||
return result;
|
||||
}
|
||||
napi_create_int32(env, cfuncs, &result);
|
||||
@ -628,7 +655,7 @@ static napi_value CoreGetPorts(napi_env env, napi_callback_info info)
|
||||
napi_value result;
|
||||
if (ret != UEC_OK) {
|
||||
napi_get_undefined(env, &result);
|
||||
USB_HILOGE(MODULE_JS_NAPI, "end call %{public}s, get ports faild ret : %{public}d", __func__, ret);
|
||||
USB_HILOGE(MODULE_JS_NAPI, "end call %{public}s, get ports failed ret : %{public}d", __func__, ret);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -916,27 +943,32 @@ static napi_value PipeGetFileDescriptor(napi_env env, napi_callback_info info)
|
||||
static auto g_controlTransferExecute = [](napi_env env, void *data) {
|
||||
USBControlTransferAsyncContext *asyncContext = (USBControlTransferAsyncContext *)data;
|
||||
std::vector<uint8_t> bufferData(asyncContext->buffer, asyncContext->buffer + asyncContext->bufferLength);
|
||||
const UsbCtrlTransfer tctrl = {asyncContext->reqType, asyncContext->request, asyncContext->value,
|
||||
asyncContext->index, asyncContext->timeOut};
|
||||
|
||||
int32_t ret = asyncContext->pipe.ControlTransfer(tctrl, bufferData);
|
||||
if ((asyncContext->reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT) {
|
||||
delete [] asyncContext->buffer;
|
||||
asyncContext->buffer = nullptr;
|
||||
} else {
|
||||
if (bufferData.size() < asyncContext->bufferLength) {
|
||||
asyncContext->bufferLength = bufferData.size();
|
||||
}
|
||||
|
||||
const UsbCtrlTransfer tctrl = {asyncContext->reqType, asyncContext->request, asyncContext->value,
|
||||
asyncContext->index, asyncContext->timeOut};
|
||||
int32_t ret;
|
||||
do {
|
||||
ret = asyncContext->pipe.ControlTransfer(tctrl, bufferData);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "ControlTransferExecute failed");
|
||||
break;
|
||||
}
|
||||
|
||||
ret = memcpy_s(asyncContext->buffer, asyncContext->bufferLength, bufferData.data(),
|
||||
asyncContext->bufferLength);
|
||||
NAPI_ASSERT_RETURN_VOID(env, ret == EOK, "ControlTransferExecute memcpy_s failed.");
|
||||
}
|
||||
if ((asyncContext->reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_IN) {
|
||||
ret = memcpy_s(asyncContext->buffer, asyncContext->bufferLength, bufferData.data(), bufferData.size());
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (ret == UEC_OK) {
|
||||
asyncContext->status = napi_ok;
|
||||
asyncContext->dataSize = bufferData.size();
|
||||
} else {
|
||||
asyncContext->status = napi_generic_failure;
|
||||
asyncContext->dataSize = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -945,7 +977,7 @@ static auto g_controlTransferComplete = [](napi_env env, napi_status status, voi
|
||||
napi_value queryResult = nullptr;
|
||||
|
||||
if (asyncContext->status == napi_ok) {
|
||||
napi_create_int32(env, asyncContext->bufferLength, &queryResult);
|
||||
napi_create_int32(env, asyncContext->dataSize, &queryResult);
|
||||
} else {
|
||||
USB_HILOGD(MODULE_JS_NAPI, "ControlTransfer failed");
|
||||
napi_create_int32(env, -1, &queryResult);
|
||||
@ -1044,25 +1076,31 @@ static napi_value PipeControlTransfer(napi_env env, napi_callback_info info)
|
||||
static auto g_bulkTransferExecute = [](napi_env env, void *data) {
|
||||
USBBulkTransferAsyncContext *asyncContext = reinterpret_cast<USBBulkTransferAsyncContext *>(data);
|
||||
std::vector<uint8_t> bufferData(asyncContext->buffer, asyncContext->buffer + asyncContext->bufferLength);
|
||||
int32_t ret = asyncContext->pipe.BulkTransfer(asyncContext->endpoint, bufferData, asyncContext->timeOut);
|
||||
|
||||
if (asyncContext->endpoint.GetDirection() == USB_ENDPOINT_DIR_OUT) {
|
||||
delete [] asyncContext->buffer;
|
||||
asyncContext->buffer = nullptr;
|
||||
} else {
|
||||
if (bufferData.size() < asyncContext->bufferLength) {
|
||||
asyncContext->bufferLength = bufferData.size();
|
||||
}
|
||||
|
||||
int32_t ret;
|
||||
do {
|
||||
ret = asyncContext->pipe.BulkTransfer(asyncContext->endpoint, bufferData, asyncContext->timeOut);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_JS_NAPI, "ControlTransferExecute failed");
|
||||
break;
|
||||
}
|
||||
|
||||
ret = memcpy_s(asyncContext->buffer, asyncContext->bufferLength, bufferData.data(), asyncContext->bufferLength);
|
||||
NAPI_ASSERT_RETURN_VOID(env, ret == EOK, "BulkTransferExecute memcpy_s failed.");
|
||||
}
|
||||
if (asyncContext->endpoint.GetDirection() == USB_ENDPOINT_DIR_IN) {
|
||||
ret = memcpy_s(asyncContext->buffer, asyncContext->bufferLength, bufferData.data(), bufferData.size());
|
||||
}
|
||||
} while (0);
|
||||
|
||||
USB_HILOGD(MODULE_JS_NAPI, "call pipe result %{public}d", ret);
|
||||
if (ret == UEC_OK) {
|
||||
asyncContext->status = napi_ok;
|
||||
asyncContext->dataSize = bufferData.size();
|
||||
} else {
|
||||
asyncContext->status = napi_generic_failure;
|
||||
asyncContext->dataSize = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1070,9 +1108,9 @@ static auto g_bulkTransferComplete = [](napi_env env, napi_status status, void *
|
||||
USBBulkTransferAsyncContext *asyncContext = reinterpret_cast<USBBulkTransferAsyncContext *>(data);
|
||||
napi_value queryResult = nullptr;
|
||||
if (asyncContext->status == napi_ok) {
|
||||
napi_create_int32(env, asyncContext->bufferLength, &queryResult);
|
||||
napi_create_int32(env, asyncContext->dataSize, &queryResult);
|
||||
} else {
|
||||
USB_HILOGD(MODULE_JS_NAPI, "BulkTransfer failed");
|
||||
USB_HILOGE(MODULE_JS_NAPI, "BulkTransfer failed");
|
||||
napi_create_int32(env, -1, &queryResult);
|
||||
}
|
||||
ProcessPromise(env, *asyncContext, queryResult);
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
RightMap rightMap;
|
||||
|
||||
void Init();
|
||||
int32_t HasRight(const std::string &deviceName, const std::string &bundleName);
|
||||
bool HasRight(const std::string &deviceName, const std::string &bundleName);
|
||||
int32_t RequestRight(const std::string &deviceName, const std::string &bundleName);
|
||||
bool AddDeviceRight(const std::string &deviceName, const std::string &bundleName);
|
||||
bool RemoveDeviceRight(const std::string &deviceName);
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
}
|
||||
|
||||
int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) override;
|
||||
int32_t HasRight(std::string deviceName) override;
|
||||
bool HasRight(std::string deviceName) override;
|
||||
int32_t RequestRight(std::string deviceName) override;
|
||||
int32_t RemoveRight(std::string deviceName) override;
|
||||
int32_t GetDevices(std::vector<UsbDevice> &deviceList) override;
|
||||
@ -87,8 +87,8 @@ public:
|
||||
bool DelDevice(uint8_t busNum, uint8_t devAddr);
|
||||
void UpdateUsbPort(int32_t portId, int32_t powerRole, int32_t dataRole, int32_t mode);
|
||||
int32_t GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &dev);
|
||||
int32_t GetDeviceInfoDescriptor(const UsbDev &uDev, std::vector<uint8_t> &decriptor, UsbDevice &dev);
|
||||
int32_t GetConfigDescriptor(UsbDevice &dev, std::vector<uint8_t> &decriptor);
|
||||
int32_t GetDeviceInfoDescriptor(const UsbDev &uDev, std::vector<uint8_t> &descriptor, UsbDevice &dev);
|
||||
int32_t GetConfigDescriptor(UsbDevice &dev, std::vector<uint8_t> &descriptor);
|
||||
|
||||
int32_t RegBulkCallback(const UsbDev &devInfo, const UsbPipe &pipe, const sptr<IRemoteObject> &cb) override;
|
||||
int32_t UnRegBulkCallback(const UsbDev &devInfo, const UsbPipe &pipe) override;
|
||||
|
@ -110,6 +110,7 @@ int32_t UsbDescriptorParser::ParseConfigDescriptor(const uint8_t *buffer, uint32
|
||||
if (interface.GetEndpointCount() > 0) {
|
||||
interfaces.push_back(interface);
|
||||
} else {
|
||||
// retry
|
||||
--i;
|
||||
}
|
||||
cursor += interfaceCursor;
|
||||
|
@ -48,6 +48,7 @@ bool UsbHostManager::DelDevice(uint8_t busNum, uint8_t devNum)
|
||||
delete devOld;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UsbHostManager::AddDevice(UsbDevice *dev)
|
||||
{
|
||||
if (dev == nullptr) {
|
||||
|
@ -20,34 +20,34 @@ namespace OHOS {
|
||||
namespace USB {
|
||||
void UsbRightManager::Init() {}
|
||||
|
||||
int32_t UsbRightManager::HasRight(const std::string &deviceName, const std::string &bundleName)
|
||||
bool UsbRightManager::HasRight(const std::string &deviceName, const std::string &bundleName)
|
||||
{
|
||||
auto itMap = rightMap.find(deviceName);
|
||||
if (itMap == rightMap.end()) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "hasRight deviceName false");
|
||||
return UEC_SERVICE_INVALID_VALUE;
|
||||
return false;
|
||||
} else {
|
||||
BundleNameList bundleNameList = itMap->second;
|
||||
auto itVevtor = std::find(bundleNameList.begin(), bundleNameList.end(), bundleName);
|
||||
if (itVevtor == bundleNameList.end()) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "hasRight bundleName false");
|
||||
return UEC_SERVICE_INVALID_VALUE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Request Right Success");
|
||||
return UEC_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t UsbRightManager::RequestRight(const std::string &deviceName, const std::string &bundleName)
|
||||
{
|
||||
if (HasRight(deviceName, bundleName) == 0) {
|
||||
if (HasRight(deviceName, bundleName)) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "device has Right ");
|
||||
return UEC_OK;
|
||||
}
|
||||
if (!AddDeviceRight(deviceName, bundleName)) {
|
||||
return UEC_SERVICE_INVALID_VALUE;
|
||||
}
|
||||
if (HasRight(deviceName, bundleName) == 0) {
|
||||
if (HasRight(deviceName, bundleName)) {
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "requestRight Success");
|
||||
return UEC_OK;
|
||||
}
|
||||
|
@ -105,12 +105,8 @@ bool UsbService::Init()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!handler_) {
|
||||
if (handler_ == nullptr) {
|
||||
handler_ = std::make_shared<UsbServerEventHandler>(eventRunner_, pms);
|
||||
if (handler_ == nullptr) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "Init failed due to create handler error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Publish(pms)) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "OnStart register to system ability manager failed.");
|
||||
@ -175,22 +171,22 @@ bool UsbService::IsCommonEventServiceAbilityExist()
|
||||
int32_t UsbService::OpenDevice(uint8_t busNum, uint8_t devAddr)
|
||||
{
|
||||
std::string name = std::to_string(busNum) + "-" + std::to_string(devAddr);
|
||||
int32_t ret = UsbService::HasRight(name);
|
||||
if (UEC_OK == ret) {
|
||||
const UsbDev dev = {busNum, devAddr};
|
||||
ret = UsbdClient::GetInstance().OpenDevice(dev);
|
||||
if (UEC_OK != ret) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "%{public}s:%{public}d OpenDevice failed ret:%{public}d", __func__, __LINE__,
|
||||
ret);
|
||||
}
|
||||
} else {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "%{public}s:%{public}d No permission ret:%{public}d", __func__, __LINE__, ret);
|
||||
ret = UEC_SERVICE_PERMISSION_DENIED;
|
||||
if (!UsbService::HasRight(name)) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "%{public}s:%{public}d No permission", __func__, __LINE__);
|
||||
return UEC_SERVICE_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
const UsbDev dev = {busNum, devAddr};
|
||||
int32_t ret = UsbdClient::GetInstance().OpenDevice(dev);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "%{public}s:%{public}d OpenDevice failed ret:%{public}d", __func__, __LINE__,
|
||||
ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbService::HasRight(std::string deviceName)
|
||||
bool UsbService::HasRight(std::string deviceName)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "calling usbRightManager HasRight");
|
||||
std::string bundleName;
|
||||
@ -199,7 +195,7 @@ int32_t UsbService::HasRight(std::string deviceName)
|
||||
return usbRightManager_->HasRight(deviceName, bundleName);
|
||||
}
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "HasRight GetBundleName false");
|
||||
return UEC_SERVICE_INNER_ERR;
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t UsbService::RequestRight(std::string deviceName)
|
||||
@ -477,9 +473,9 @@ static int32_t FillDevStrings(UsbDevice &dev)
|
||||
return UEC_OK;
|
||||
}
|
||||
|
||||
int32_t UsbService::GetDeviceInfoDescriptor(const UsbDev &uDev, std::vector<uint8_t> &decriptor, UsbDevice &dev)
|
||||
int32_t UsbService::GetDeviceInfoDescriptor(const UsbDev &uDev, std::vector<uint8_t> &descriptor, UsbDevice &dev)
|
||||
{
|
||||
int32_t ret = UsbdClient::GetInstance().GetRawDescriptor(uDev, decriptor);
|
||||
int32_t ret = UsbdClient::GetInstance().GetRawDescriptor(uDev, descriptor);
|
||||
if (ret != UEC_OK) {
|
||||
UsbdClient::GetInstance().CloseDevice(uDev);
|
||||
USB_HILOGE(MODULE_USB_SERVICE,
|
||||
@ -488,8 +484,8 @@ int32_t UsbService::GetDeviceInfoDescriptor(const UsbDev &uDev, std::vector<uint
|
||||
__func__, __LINE__, ret, uDev.busNum, uDev.devAddr);
|
||||
return ret;
|
||||
}
|
||||
uint8_t *buffer = decriptor.data();
|
||||
uint32_t length = decriptor.size();
|
||||
uint8_t *buffer = descriptor.data();
|
||||
uint32_t length = descriptor.size();
|
||||
if ((!buffer) || (length == 0)) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE,
|
||||
"%{public}s:%{public}d GetRawDescriptor failed len=%{public}d busNum:%{public}d "
|
||||
@ -510,11 +506,11 @@ int32_t UsbService::GetDeviceInfoDescriptor(const UsbDev &uDev, std::vector<uint
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbService::GetConfigDescriptor(UsbDevice &dev, std::vector<uint8_t> &decriptor)
|
||||
int32_t UsbService::GetConfigDescriptor(UsbDevice &dev, std::vector<uint8_t> &descriptor)
|
||||
{
|
||||
std::vector<USBConfig> configs;
|
||||
uint8_t *buffer = decriptor.data();
|
||||
uint32_t length = decriptor.size();
|
||||
uint8_t *buffer = descriptor.data();
|
||||
uint32_t length = descriptor.size();
|
||||
uint32_t cursor = CURSOR_INIT;
|
||||
int32_t ret = UEC_OK;
|
||||
for (uint8_t i = 0; i < dev.GetDescConfigCount(); ++i) {
|
||||
@ -542,7 +538,7 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "%{public}s:%{public}d busNum:%{public}d devAddr:%{public}d", __func__, __LINE__,
|
||||
busNum, devAddr);
|
||||
const UsbDev uDev = {busNum, devAddr};
|
||||
std::vector<uint8_t> decriptor;
|
||||
std::vector<uint8_t> descriptor;
|
||||
|
||||
int32_t ret = UsbdClient::GetInstance().OpenDevice(uDev);
|
||||
if (ret != UEC_OK) {
|
||||
@ -550,12 +546,12 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = GetDeviceInfoDescriptor(uDev, decriptor, dev);
|
||||
ret = GetDeviceInfoDescriptor(uDev, descriptor, dev);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "%{public}s:%{public}d GetDeviceInfoDescriptor ret=%{public}d", __func__,
|
||||
__LINE__, ret);
|
||||
}
|
||||
ret = GetConfigDescriptor(dev, decriptor);
|
||||
ret = GetConfigDescriptor(dev, descriptor);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "%{public}s:%{public}d GetConfigDescriptor ret=%{public}d", __func__, __LINE__,
|
||||
ret);
|
||||
@ -591,6 +587,7 @@ bool UsbService::AddDevice(uint8_t busNum, uint8_t devAddr)
|
||||
delete devInfo;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UsbService::DelDevice(uint8_t busNum, uint8_t devAddr)
|
||||
{
|
||||
USB_HILOGI(MODULE_USBD, "%{public}s:%{public}d entry", __func__, __LINE__);
|
||||
|
@ -38,6 +38,11 @@ UsbServiceSubscriber::UsbServiceSubscriber() {}
|
||||
int32_t UsbServiceSubscriber::PortChangedEvent(int32_t portId, int32_t powerRole, int32_t dataRole, int32_t mode)
|
||||
{
|
||||
auto pms = DelayedSpSingleton<UsbService>::GetInstance();
|
||||
if (pms == nullptr) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "failed to GetInstance");
|
||||
return UEC_SERVICE_GET_USB_SERVICE_FAILED;
|
||||
}
|
||||
|
||||
Want want;
|
||||
want.SetAction(CommonEventSupport::COMMON_EVENT_USB_PORT_CHANGED);
|
||||
pms->UpdateUsbPort(portId, powerRole, dataRole, mode);
|
||||
@ -111,8 +116,11 @@ int32_t UsbServiceSubscriber::DeviceEvent(const UsbInfo &info)
|
||||
USB_HILOGW(MODULE_USBD, "%{public}s:%{public}d status:%{public}d bus:%{public}d dev:%{public}d", __func__, __LINE__,
|
||||
status, busNum, devAddr);
|
||||
auto pms = DelayedSpSingleton<UsbService>::GetInstance();
|
||||
USB_HILOGW(MODULE_USBD, "%{public}s:%{public}d status:%{public}d pms:%{public}s", __func__, __LINE__, status,
|
||||
pms == nullptr ? "NULL" : "OK");
|
||||
if (pms == nullptr) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "failed to GetInstance");
|
||||
return UEC_SERVICE_GET_USB_SERVICE_FAILED;
|
||||
}
|
||||
|
||||
if (status == ACT_DEVUP) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "usb attached");
|
||||
pms->AddDevice(busNum, devAddr);
|
||||
|
@ -2,8 +2,8 @@
|
||||
"services" : [{
|
||||
"name" : "usb_service",
|
||||
"path" : ["/system/bin/sa_main", "/system/profile/usb_service.xml"],
|
||||
"uid" : "system",
|
||||
"gid" : ["system", "shell"]
|
||||
"uid" : "usb",
|
||||
"gid" : ["usb", "shell"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
|
||||
int32_t GetDevices(std::vector<UsbDevice> &deviceList) override;
|
||||
int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) override;
|
||||
int32_t HasRight(std::string deviceName) override;
|
||||
bool HasRight(std::string deviceName) override;
|
||||
int32_t RequestRight(std::string deviceName) override;
|
||||
int32_t RemoveRight(std::string deviceName) override;
|
||||
int32_t GetCurrentFunctions(int32_t &funcs) override;
|
||||
|
@ -170,12 +170,13 @@ int32_t UsbServerProxy::GetDeviceMessageParcel(MessageParcel &data, UsbDevice &d
|
||||
|
||||
int32_t UsbServerProxy::GetDeviceConfigsMessageParcel(MessageParcel &data, std::vector<USBConfig> &configs)
|
||||
{
|
||||
int32_t tmp, configCount;
|
||||
uint32_t configCount;
|
||||
uint8_t tui8;
|
||||
std::string tstr;
|
||||
data.ReadInt32(tmp);
|
||||
configCount = tmp;
|
||||
for (int32_t i = 0; i < configCount; ++i) {
|
||||
data.ReadUint32(configCount);
|
||||
|
||||
int32_t tmp;
|
||||
for (uint32_t i = 0; i < configCount; ++i) {
|
||||
USBConfig config;
|
||||
data.ReadInt32(tmp);
|
||||
config.SetId(tmp);
|
||||
@ -279,24 +280,30 @@ int32_t UsbServerProxy::OpenDevice(uint8_t busNum, uint8_t devAddr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbServerProxy::HasRight(std::string deviceName)
|
||||
bool UsbServerProxy::HasRight(std::string deviceName)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageOption option;
|
||||
MessageParcel reply;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
|
||||
RETURN_IF_WITH_RET(remote == nullptr, false);
|
||||
if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
|
||||
USB_HILOGE(MODULE_INNERKIT, "UsbServerProxy::%{public}s write descriptor failed!", __func__);
|
||||
return UEC_INTERFACE_WRITE_PARCEL_ERROR;
|
||||
return false;
|
||||
}
|
||||
WRITE_PARCEL_WITH_RET(data, String, deviceName, UEC_INTERFACE_WRITE_PARCEL_ERROR);
|
||||
|
||||
WRITE_PARCEL_WITH_RET(data, String, deviceName, false);
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(IUsbSrv::USB_FUN_HAS_RIGHT), data, reply, option);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "UsbServerProxy::%{public}s SendRequest is failed, error code: %{public}d",
|
||||
__func__, ret);
|
||||
return false;
|
||||
}
|
||||
return ret;
|
||||
|
||||
bool result = false;
|
||||
READ_PARCEL_WITH_RET(reply, Bool, result, false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UsbServerProxy::RequestRight(std::string deviceName)
|
||||
|
@ -263,7 +263,9 @@ int32_t UsbServerStub::DoHasRight(MessageParcel &data, MessageParcel &reply, Mes
|
||||
{
|
||||
std::string deviceName = "";
|
||||
READ_PARCEL_WITH_RET(data, String, deviceName, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
return HasRight(deviceName);
|
||||
WRITE_PARCEL_WITH_RET(reply, Bool, HasRight(deviceName), UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
|
||||
return UEC_OK;
|
||||
}
|
||||
|
||||
int32_t UsbServerStub::DoRequestRight(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
@ -695,7 +697,7 @@ int32_t UsbServerStub::SetDeviceConfigsMessageParcel(std::vector<USBConfig> &con
|
||||
WRITE_PARCEL_WITH_RET(data, Uint8, config.GetiConfiguration(), UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, String, config.GetName(), UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, config.GetInterfaceCount(), UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, config.GetInterfaceCount(), UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "%{public}s devInfo=%{public}s", __func__, config.ToString().c_str());
|
||||
int32_t ret = SetDeviceInterfacesMessageParcel(config.GetInterfaces(), data);
|
||||
if (ret) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "usb_srv_client.h"
|
||||
#include "ashmem.h"
|
||||
#include "securec.h"
|
||||
#include "usb_errors.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "usb_callback_test.h"
|
||||
|
||||
|
@ -353,8 +353,8 @@ HWTEST_F(UsbCoreTest, UsbFunctionsToString005, TestSize.Level1)
|
||||
/**
|
||||
* @tc.name: UsbHasRight001
|
||||
* @tc.desc: Test functions of HasRight
|
||||
* @tc.desc: int32_t HasRight(std::string deviceName)
|
||||
* @tc.desc: 正向测试:代码正常运行,返回结果为-1
|
||||
* @tc.desc: bool HasRight(std::string deviceName)
|
||||
* @tc.desc: Before RequestRight, HasRight return false.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbCoreTest, UsbHasRight001, TestSize.Level1)
|
||||
@ -362,17 +362,17 @@ HWTEST_F(UsbCoreTest, UsbHasRight001, TestSize.Level1)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbHasRight001: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_80";
|
||||
int32_t result = UsbSrvClient.HasRight(deviceName);
|
||||
bool result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight001 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result != 0);
|
||||
ASSERT_FALSE(result);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbHasRight001: SetConfig");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UsbHasRight002
|
||||
* @tc.desc: Test functions of HasRight
|
||||
* @tc.desc: int32_t HasRight(std::string deviceName)
|
||||
* @tc.desc: 反向测试:代码正常运行,返回结果为0
|
||||
* @tc.desc: bool HasRight(std::string deviceName)
|
||||
* @tc.desc: After RequestRight, HasRight return true.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbCoreTest, UsbHasRight002, TestSize.Level1)
|
||||
@ -380,23 +380,23 @@ HWTEST_F(UsbCoreTest, UsbHasRight002, TestSize.Level1)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbHasRight002: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_80";
|
||||
int32_t result = UsbSrvClient.HasRight(deviceName);
|
||||
bool result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight002 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result != 0);
|
||||
result = UsbSrvClient.RequestRight(deviceName);
|
||||
ASSERT_FALSE(result);
|
||||
int32_t ret = UsbSrvClient.RequestRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight002 RequestRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight002 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_TRUE(result);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbHasRight002: SetConfig");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UsbHasRight003
|
||||
* @tc.desc: Test functions of HasRight
|
||||
* @tc.desc: int32_t HasRight(std::string deviceName)
|
||||
* @tc.desc: 反向测试:代码正常运行,返回结果为-1
|
||||
* @tc.desc: bool HasRight(std::string deviceName)
|
||||
* @tc.desc: After RemoveRight, HasRight return false.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbCoreTest, UsbHasRight003, TestSize.Level1)
|
||||
@ -404,24 +404,24 @@ HWTEST_F(UsbCoreTest, UsbHasRight003, TestSize.Level1)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbHasRight003: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_80";
|
||||
int32_t result = UsbSrvClient.HasRight(deviceName);
|
||||
bool result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight003 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.RemoveRight(deviceName);
|
||||
ASSERT_TRUE(result);
|
||||
int32_t ret = UsbSrvClient.RemoveRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight003 RemoveRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
deviceName = "device_81";
|
||||
result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight003 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result != 0);
|
||||
ASSERT_FALSE(result);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbHasRight003: SetConfig");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UsbHasRight004
|
||||
* @tc.desc: Test functions of HasRight
|
||||
* @tc.desc: int32_t HasRight(std::string deviceName)
|
||||
* @tc.desc: 反向测试:代码正常运行,返回结果为0
|
||||
* @tc.desc: bool HasRight(std::string deviceName)
|
||||
* @tc.desc: RequestRight then RemoveRight
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbCoreTest, UsbHasRight004, TestSize.Level1)
|
||||
@ -429,18 +429,18 @@ HWTEST_F(UsbCoreTest, UsbHasRight004, TestSize.Level1)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbHasRight004: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_82";
|
||||
int32_t result = UsbSrvClient.HasRight(deviceName);
|
||||
bool result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight004 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result != 0);
|
||||
result = UsbSrvClient.RequestRight(deviceName);
|
||||
ASSERT_FALSE(result);
|
||||
int32_t ret = UsbSrvClient.RequestRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight004 RequestRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbHasRight004 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.RemoveRight(deviceName);
|
||||
ASSERT_TRUE(result);
|
||||
ret = UsbSrvClient.RemoveRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 RemoveRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbHasRight004: SetConfig");
|
||||
}
|
||||
|
||||
@ -448,7 +448,7 @@ HWTEST_F(UsbCoreTest, UsbHasRight004, TestSize.Level1)
|
||||
* @tc.name: Usbrequestright001
|
||||
* @tc.desc: Test functions of requestright
|
||||
* @tc.desc: int32_t requestright(std::string deviceName)
|
||||
* @tc.desc: 正向测试:代码正常运行
|
||||
* @tc.desc: RequestRight then RemoveRight
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbCoreTest, Usbrequestright001, TestSize.Level1)
|
||||
@ -456,40 +456,17 @@ HWTEST_F(UsbCoreTest, Usbrequestright001, TestSize.Level1)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : Usbrequestright001: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_83";
|
||||
int32_t result = UsbSrvClient.RequestRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright001 RequestRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.HasRight(deviceName);
|
||||
int32_t ret = UsbSrvClient.RequestRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright001 RequestRight=%{public}d", ret);
|
||||
ASSERT_EQ(ret, 0);
|
||||
bool result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright001 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.RemoveRight(deviceName);
|
||||
ASSERT_TRUE(result);
|
||||
ret = UsbSrvClient.RemoveRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 RemoveRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : Usbrequestright001: SetConfig");
|
||||
}
|
||||
/**
|
||||
* @tc.name: Usbrequestright002
|
||||
* @tc.desc: Test functions of requestright
|
||||
* @tc.desc: int32_t requestright(std::string deviceName)
|
||||
* @tc.desc: 正向测试:代码正常运行
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbCoreTest, Usbrequestright002, TestSize.Level1)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : Usbrequestright002: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_84";
|
||||
int32_t result = UsbSrvClient.RequestRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright002 RequestRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright002 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.RemoveRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 RemoveRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : Usbrequestright002: SetConfig");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Usbrequestright003
|
||||
@ -502,18 +479,18 @@ HWTEST_F(UsbCoreTest, Usbrequestright003, TestSize.Level1)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : Usbrequestright003: SetConfig");
|
||||
auto &UsbSrvClient = UsbSrvClient::GetInstance();
|
||||
std::string deviceName = "device_81";
|
||||
int32_t result = UsbSrvClient.HasRight(deviceName);
|
||||
bool result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result != 0);
|
||||
result = UsbSrvClient.RequestRight(deviceName);
|
||||
ASSERT_FALSE(result);
|
||||
int32_t ret = UsbSrvClient.RequestRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 RequestRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
result = UsbSrvClient.HasRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 HasRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
result = UsbSrvClient.RemoveRight(deviceName);
|
||||
ASSERT_TRUE(result);
|
||||
ret = UsbSrvClient.RemoveRight(deviceName);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::Usbrequestright003 RemoveRight=%{public}d", result);
|
||||
ASSERT_TRUE(result == 0);
|
||||
ASSERT_EQ(ret, 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : Usbrequestright003: SetConfig");
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
@ -19,11 +19,14 @@ using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::USB;
|
||||
|
||||
static const int32_t DEFAULT_PORT_ID = 1;
|
||||
static const int32_t DEFAULT_ROLE_HOST = 1;
|
||||
static const int32_t DEFAULT_ROLE_DEVICE = 2;
|
||||
static constexpr int32_t DEFAULT_PORT_ID = 1;
|
||||
static constexpr int32_t DEFAULT_ROLE_HOST = 1;
|
||||
static constexpr int32_t DEFAULT_ROLE_DEVICE = 2;
|
||||
static constexpr int32_t MIN_ARG_NUM = 3;
|
||||
static constexpr uint32_t CMD_INDEX = 1;
|
||||
static constexpr uint32_t PARAM_INDEX = 2;
|
||||
|
||||
static const int32_t HOST_MODE = 2;
|
||||
static constexpr int32_t HOST_MODE = 2;
|
||||
|
||||
static UsbSrvClient &g_usbClient = UsbSrvClient::GetInstance();
|
||||
|
||||
@ -33,7 +36,7 @@ static void PrintHelp()
|
||||
printf("-p 0: Query Port\n");
|
||||
printf("-p 1: Switch to host\n");
|
||||
printf("-p 2: Switch to device:\n");
|
||||
printf("-f 0: Query fucntion\n");
|
||||
printf("-f 0: Query function\n");
|
||||
printf("-f 1: Switch to function:acm\n");
|
||||
printf("-f 2: Switch to function:ecm\n");
|
||||
printf("-f 3: Switch to function:acm&ecm\n");
|
||||
@ -108,18 +111,29 @@ static void PortSwitch(UsbSrvClient &g_usbClient, int32_t mode)
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool isNumber(string_view strv)
|
||||
{
|
||||
return (strv.find_first_not_of("0123456789") == strv.npos);
|
||||
}
|
||||
|
||||
int32_t main(int32_t argc, char *argv[])
|
||||
{
|
||||
if ((argc < 1) || (strcmp(argv[1], "-h") == 0)) {
|
||||
if (argc < MIN_ARG_NUM) {
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((!strcmp(argv[1], "-f"))) {
|
||||
int32_t mode = stoi(argv[2]);
|
||||
if (!isNumber(argv[PARAM_INDEX])) {
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mode;
|
||||
if ((!strcmp(argv[CMD_INDEX], "-f"))) {
|
||||
mode = stoi(argv[PARAM_INDEX]);
|
||||
FunctionSwitch(g_usbClient, mode);
|
||||
} else if (!strcmp(argv[1], "-p")) {
|
||||
int32_t mode = stoi(argv[2]);
|
||||
} else if (!strcmp(argv[CMD_INDEX], "-p")) {
|
||||
mode = stoi(argv[PARAM_INDEX]);
|
||||
PortSwitch(g_usbClient, mode);
|
||||
} else {
|
||||
printf("param incorrect: please input -h for help\n");
|
||||
|
Loading…
Reference in New Issue
Block a user