Merge branch 'master' of gitee.com:openharmony/drivers_framework into drv

This commit is contained in:
JING
2021-05-21 16:38:09 +08:00
committed by Gitee
249 changed files with 14792 additions and 2118 deletions
+4
View File
@@ -0,0 +1,4 @@
*.o
*.a
*.d
*.cmd
+99
View File
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 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.
Notes:
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun@huawei.com.
-->
<!-- 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:
" == &gt;
& == &gt;
' == &gt;
< == &gt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="license" name="GPL" path=".*" desc="linux kernel adapter codes"/>
<policyitem type="license" name="BSD" path=".*" desc="huawei codes"/>
<!--policyitem type="compatibility" name="GPL" path=".*" desc="linux kernel adapter codes"/-->
<!--policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="linux kernel adapter 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|*.cmd|*.hcb|*.swp|hc-gen"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filename" name="README.OpenSource"/>
<filteritem type="filename" name="README"/>
<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="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="filepath" name="core/adapter/.*" desc="it's not a repo"/>
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies" >
<filteritem type="filepath" name="dir name underproject/.*" 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="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>
+3 -3
View File
@@ -156,9 +156,9 @@ For details, see [WLAN Overview](https://gitee.com/openharmony/docs/blob/master
drivers\_framework
[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md)
+2 -6
View File
@@ -156,13 +156,9 @@ HDF驱动框架详细开发请参考[驱动开发指南](https://gitee.com/openh
drivers\_framework
[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README_zh.md)
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_khdf_liteos/blob/master/README_zh.md)
<a name="table19581927144220"></a>
<table><tbody></tbody>
</table>
[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md)
+1 -1
View File
@@ -41,7 +41,7 @@ static bool DeviceResourceIfaceConstruct(struct DeviceResourceIface *instance, D
HcsIfaceConstruct(instance);
break;
default:
HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, type);
HDF_LOGE("%s: Currently, this configuration type is not supported, the type is %d", __func__, type);
return false;
}
return true;
@@ -71,7 +71,7 @@ static inline uint32_t HcsGetPrefix(const char *start)
#define HCS_PREFIX_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1)
#define HCS_BYTE_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1)
#define HCS_WORD_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 2)
#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1)) // add the '\0'.
#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1))
int32_t HcsGetDataTypeOffset(const char *start);
int32_t HcsGetAttrLength(const char *start);
int32_t HcsGetNodeOrAttrLength(const char *start);
@@ -82,4 +82,4 @@ bool HcsSwapToUint16(uint16_t *value, const char *realValue, uint32_t type);
bool HcsSwapToUint32(uint32_t *value, const char *realValue, uint32_t type);
bool HcsSwapToUint64(uint64_t *value, const char *realValue, uint32_t type);
#endif // HCS_BLOB_IF_H
#endif /* HCS_BLOB_IF_H */
@@ -13,9 +13,9 @@
#define TREE_STACK_MAX 64
struct TreeStack {
uint32_t offset; // the offset of node in blob
struct DeviceResourceNode *node; // the node is the head node of every layer tree
uint32_t offset; // The offset of the node in the blob.
struct DeviceResourceNode *node; // The head node of a layer tree.
};
int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, struct DeviceResourceNode **root);
#endif // HCS_GENERATE_TREE_H
#endif /* HCS_GENERATE_TREE_H */
@@ -13,4 +13,4 @@
bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNode **root);
#endif // HCS_PARSER_H
#endif /* HCS_PARSER_H */
@@ -56,4 +56,4 @@ const struct DeviceResourceNode *HcsGetNodeByRefAttr(const struct DeviceResource
#endif
#endif /* __cplusplus */
#endif // HCS_TREE_IF_H
#endif /* HCS_TREE_IF_H */
+3 -3
View File
@@ -13,7 +13,7 @@
static bool g_byteAlign = false;
bool HcsIsByteAlign()
bool HcsIsByteAlign(void)
{
return g_byteAlign;
}
@@ -185,7 +185,7 @@ static bool CheckHcsBlobLength(uint32_t length, struct HbcHeader *header)
HDF_LOGI("%s: the blobLength: %u, byteAlign: %d", __func__, blobLength, g_byteAlign);
}
if ((length != blobLength) || (blobLength < minLength)) {
HDF_LOGE("%s failed, Hcsblob file length is %u, But the length of calculation is %u",
HDF_LOGE("%s failed, Hcsblob file length is %u, but the calculated length is %u",
__func__, length, blobLength);
return false;
}
@@ -201,7 +201,7 @@ bool HcsCheckBlobFormat(const char *start, uint32_t length)
}
header = (struct HbcHeader *)start;
if (header->magicNumber != HBC_MAGIC_NUMBER) {
HDF_LOGE("%s failed, the magic of HBC is %x", __func__, header->magicNumber);
HDF_LOGE("%s failed, the magic number of HBC is %x", __func__, header->magicNumber);
return false;
}
if (!CheckHcsBlobLength(length, header)) {
@@ -53,7 +53,7 @@ static bool UpdateTreeStack(struct TreeStack **treeStack, int32_t *treeLayer, st
uint32_t offset)
{
if (*treeLayer >= (TREE_STACK_MAX - 1)) {
HDF_LOGE("%s failed, the treeLayer error. treeLayer: %d", __func__, *treeLayer);
HDF_LOGE("%s failed, the treeLayer error, treeLayer: %d", __func__, *treeLayer);
return false;
}
(*treeLayer)++;
@@ -83,7 +83,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM
{
int32_t termOffset = HcsGetNodeOrAttrLength(treeStart + offset);
if (termOffset <= 0) {
HDF_LOGE("%s failed, HcsGetNodeOrAttrLength failed, errno: %d", __func__, termOffset);
HDF_LOGE("%s failed, HcsGetNodeOrAttrLength error, errno: %d", __func__, termOffset);
return HDF_FAILURE;
}
@@ -111,7 +111,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM
}
parentOrCurNode = GetParentNode(offset, *treeStack, treeLayerOrMemLen, termOffset);
if (!AddAttrInNode(treeStart + offset, parentOrCurNode, treeMem)) {
HDF_LOGE("%s failed, the AddAttrInNode error", __func__);
HDF_LOGE("%s failed, AddAttrInNode error", __func__);
return HDF_FAILURE;
}
break;
@@ -136,14 +136,14 @@ int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, st
while ((offset < length) && (offset >= 0)) {
int32_t eachOffset = ParseByteCode(treeStart, offset, &treeMem, &treeStack, &treeLayerOrMemLen);
if (eachOffset <= 0) {
HDF_LOGE("%s failed, the ParseByteCode error", __func__);
HDF_LOGE("%s failed, ParseByteCode error", __func__);
treeLayerOrMemLen = eachOffset;
break;
}
offset += eachOffset;
}
if ((treeMem != NULL) && (root != NULL) && (treeLayerOrMemLen > 0)) {
// the treeStack[1] is root
// The treeStack[1] is root
*root = treeStack[1].node;
}
OsalMemFree(treeStack);
+3 -3
View File
@@ -23,19 +23,19 @@ bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNod
{
int32_t nodeLength = HcsGetNodeLength(hcsBlob + offset);
if (nodeLength < 0) {
HDF_LOGE("%s failed, HcsGetNodeLength failed", __func__);
HDF_LOGE("%s failed, HcsGetNodeLength error", __func__);
return false;
}
int32_t treeMemLength = GetHcsTreeSize(hcsBlob + offset, nodeLength);
if (treeMemLength <= 0) {
HDF_LOGE("%s failed, GetHcsTreeSize failed", __func__);
HDF_LOGE("%s failed, GetHcsTreeSize error, treeMemLength = %d", __func__, treeMemLength);
return false;
}
char *treeMem = (char *)OsalMemCalloc(treeMemLength);
if (treeMem == NULL) {
HDF_LOGE("%s failed, OsalMemCalloc Device tree memory failed", __func__);
HDF_LOGE("%s failed, OsalMemCalloc error", __func__);
return false;
}
int32_t treeLayer = GenerateCfgTree(hcsBlob + offset, nodeLength, treeMem, root);
+15 -15
View File
@@ -36,7 +36,7 @@ bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName)
}
if (!HcsSwapToUint8(&value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return false;
}
return value ? true : false;
@@ -44,7 +44,7 @@ bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName)
#define RETURN_DEFAULT_VALUE(attr, attrName, value, def) do { \
if (((attr) == NULL) || ((attr)->value == NULL) || ((value) == NULL)) { \
HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, return the default value", \
HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, the value is default value", \
__func__, ((attrName) == NULL) ? "error attrName" : (attrName)); \
if ((value) != NULL) { \
*(value) = (def); \
@@ -60,7 +60,7 @@ int32_t HcsGetUint8(const struct DeviceResourceNode *node, const char *attrName,
if (!HcsSwapToUint8(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -73,7 +73,7 @@ int32_t HcsGetUint16(const struct DeviceResourceNode *node, const char *attrName
if (!HcsSwapToUint16(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -86,7 +86,7 @@ int32_t HcsGetUint32(const struct DeviceResourceNode *node, const char *attrName
if (!HcsSwapToUint32(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -99,7 +99,7 @@ int32_t HcsGetUint64(const struct DeviceResourceNode *node, const char *attrName
if (!HcsSwapToUint64(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -116,7 +116,7 @@ static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t
return NULL;
}
if (index >= count) {
HDF_LOGE("%s failed, the index: %u >= count: %u", __func__, index, count);
HDF_LOGE("%s failed, index: %u >= count: %u", __func__, index, count);
return NULL;
}
for (i = 0; i < index; i++) {
@@ -144,7 +144,7 @@ int32_t HcsGetUint8ArrayElem(const struct DeviceResourceNode *node, const char *
}
if (!HcsSwapToUint8(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_ERR_INVALID_OBJECT;
}
return HDF_SUCCESS;
@@ -165,7 +165,7 @@ int32_t HcsGetUint16ArrayElem(const struct DeviceResourceNode *node, const char
}
if (!HcsSwapToUint16(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_ERR_INVALID_OBJECT;
}
return HDF_SUCCESS;
@@ -186,7 +186,7 @@ int32_t HcsGetUint32ArrayElem(const struct DeviceResourceNode *node, const char
}
if (!HcsSwapToUint32(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_ERR_INVALID_OBJECT;
}
return HDF_SUCCESS;
@@ -202,7 +202,7 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char
realValue = GetArrayElem(attr, index);
if ((realValue == NULL) || !HcsSwapToUint64(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
*value = def;
HDF_LOGE("%s failed, the realValue is NULL or incorrect prefix code", __func__);
HDF_LOGE("%s failed, invalid realValue (NULL) or incorrect prefix", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -211,11 +211,11 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char
#define CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result) do { \
if ((result) == HDF_ERR_INVALID_OBJECT) { \
(ret) = HDF_ERR_INVALID_OBJECT; \
HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \
HDF_LOGE("%s failed, the result is %d", __func__, (result)); \
continue; \
} \
if ((result) != HDF_SUCCESS) { \
HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \
HDF_LOGE("%s failed, the result is %d", __func__, (result)); \
return result; \
} \
} while (0)
@@ -316,7 +316,7 @@ int32_t HcsGetString(const struct DeviceResourceNode *node, const char *attrName
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
if (HcsGetPrefix(attr->value) != CONFIG_STRING) {
*value = def;
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
HDF_LOGE("%s failed, incorrect prefix", __func__);
return HDF_FAILURE;
}
*value = attr->value + HCS_PREFIX_LENGTH;
@@ -366,7 +366,7 @@ const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResour
const struct DeviceResourceNode *curNode = NULL;
struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if ((attrValue == NULL) || (instance == NULL) || (instance->GetRootNode == NULL)) {
HDF_LOGE("%s failed, attrValue is NULL or DeviceResourceGetIfaceInstance error", __func__);
HDF_LOGE("%s failed, attrValue or instance error", __func__);
return NULL;
}
curNode = (node != NULL) ? node : instance->GetRootNode();
@@ -19,7 +19,7 @@
using namespace testing::ext;
namespace ConfigTest {
const int8_t HDF_MSG_RESUL_DEFALUT = 3;
const int8_t HDF_MSG_RESULT_DEFAULT = 3;
// hcs config test case number
enum HdfTestCaseCmd {
@@ -84,23 +84,19 @@ void HdfConfigTest::TearDownTestCase()
HdfTestCloseService();
}
void HdfConfigTest::SetUp()
{
}
void HdfConfigTest::SetUp() {}
void HdfConfigTest::TearDown()
{
}
void HdfConfigTest::TearDown() {}
/**
* @tc.name: HslTestCreateDMHslToTree001
* @tc.desc: Create a config tree, enter config test
* @tc.desc: Create a configuration tree and start configuration test
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESULT_DEFAULT};
printf("HdfConfigTest enter\n\r");
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -111,9 +107,9 @@ HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -123,9 +119,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -135,9 +131,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -147,9 +143,9 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -159,9 +155,9 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -171,9 +167,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -183,9 +179,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -195,9 +191,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -207,9 +203,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -219,9 +215,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -231,9 +227,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -243,9 +239,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -255,9 +251,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -268,9 +264,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -280,9 +276,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -292,9 +288,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -304,9 +300,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -316,9 +312,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -328,9 +324,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -341,9 +337,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -353,9 +349,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -365,9 +361,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -377,9 +373,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -389,9 +385,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -401,9 +397,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -414,9 +410,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -426,9 +422,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -438,9 +434,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -450,9 +446,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -462,9 +458,9 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -474,9 +470,9 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -486,9 +482,9 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -498,9 +494,9 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -510,9 +506,9 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -522,9 +518,9 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -534,9 +530,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -546,9 +542,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -559,9 +555,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -571,9 +567,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESULT_DEFAULT};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
@@ -583,9 +579,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000DQ0TB
*/
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level1)
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level0)
{
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESUL_DEFALUT};
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESULT_DEFAULT};
printf("HdfConfigTest last enter\n\r");
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
+236 -19
View File
@@ -9,10 +9,11 @@
* @addtogroup Core
* @{
*
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
* @brief Provides functions to use the OpenHarmony Driver Foundation (HDF).
*
* The HDF implements driver framework capabilities such as driver loading, service management,
* and driver message model. You can develop drivers based on the HDF.
* The HDF implements driver framework capabilities such as driver loading, service management, driver message model,
* and power management.
* You can develop drivers based on the HDF.
*
* @since 1.0
*/
@@ -20,8 +21,8 @@
/**
* @file hdf_sbuf.h
*
* @brief Defines functions related to a <b>HdfSBuf</b>. The HDF provides data serialization and deserialization
* capabilities for data transmission between user-mode applications and kernel-mode drivers.
* @brief Declares functions related to the HDF SBUF. The HDF provides data serialization and deserialization
* capabilities for data transmission between user-space applications and kernel-space drivers.
*
* @since 1.0
*/
@@ -33,19 +34,24 @@
#ifdef __cplusplus
extern "C" {
#else
typedef uint16_t char16_t;
#endif /* __cplusplus */
struct HdfSBuf;
struct HdfSbufImpl;
struct HdfRemoteService;
/**
* @brief Defines a <b>HdfSBuf</b>.
* @brief Enumerates HDF SBUF types.
*
* @since 1.0
*/
struct HdfSBuf {
size_t writePos; /**< Current write position */
size_t readPos; /**< Current read position */
size_t capacity; /**< Storage capacity, at most 512 KB. */
uint8_t *data; /**< Pointer to data storage */
bool isBind; /**< Whether to bind the externally transferred pointer for data storage */
enum HdfSbufType {
SBUF_RAW = 0, /* SBUF used for communication between the user space and the kernel space */
SBUF_IPC, /* SBUF used for inter-process communication (IPC) */
SBUF_IPC_HW, /* Reserved for extension */
SBUF_TYPE_MAX, /* Maximum value of the SBUF type */
};
/**
@@ -60,6 +66,18 @@ struct HdfSBuf {
*/
bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize);
/**
* @brief Writes unpadded data to a <b>SBuf</b>. You can call {@link HdfSbufReadUnpadBuffer} to read the unpadded data.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param data Indicates the pointer to the data to write. The value cannot be a null pointer.
* @param writeSize Indicates the size of the data to write. The value cannot be <b>0</b>.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t writeSize);
/**
* @brief Writes a 64-bit unsigned integer to a <b>SBuf</b>.
*
@@ -159,13 +177,133 @@ bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value);
*/
bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value);
/**
* @brief Writes a wide character string to a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param value Indicates the pointer to the wide character string to write.
* @param size Indicates the size of the wide character string to write.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size);
/**
* @brief Writes a floating-point number to a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param value Indicates the floating-point number to write.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufWriteFloat(struct HdfSBuf *sbuf, float value);
/**
* @brief Writes a double-precision floating-point number to a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param value Indicates the double-precision floating-point number to write.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufWriteDouble(struct HdfSBuf *sbuf, double value);
/**
* @brief Writes a file descriptor to a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param fd Indicates the file descriptor to write.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufWriteFileDescriptor(struct HdfSBuf *sbuf, int fd);
/**
* @brief Writes an IPC service to a <b>SBuf</b>. The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param service Indicates the pointer to the IPC service to write.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteService *service);
/**
* @brief Reads an IPC service from a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @return Returns the pointer to the IPC service object if the operation is successful;
* returns a null pointer otherwise.
*
* @since 1.0
*/
struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf);
/**
* @brief Reads a file descriptor from a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @return Returns a valid file descriptor if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int HdfSbufReadFileDescriptor(struct HdfSBuf *sbuf);
/**
* @brief Reads a double-precision floating-point number from a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param value Indicates the pointer to the double-precision floating-point number read,
* which is requested by the caller.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufReadDouble(struct HdfSBuf *sbuf, double *value);
/**
* @brief Reads a floating-point number from a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param value Indicates the pointer to the floating-point number read, which is requested by the caller.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *value);
/**
* @brief Reads a wide character string from a <b>SBuf</b>.
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @return Returns the pointer to the wide character string if the operation is successful;
* returns a null pointer otherwise.
*
* @since 1.0
*/
const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf);
/**
* @brief Reads a data segment from a <b>SBuf</b>.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param data Indicates the double pointer to the data read. The data read is stored in <b>*data</b>,
* which is requested by the caller. The memory pointed to by <b>*data</b> is managed by the <b>SBuf</b>
* and they share the same lifecycle.
* which is requested by the caller. The memory pointed to by <b>*data</b> is managed by
* the <b>SBuf</b> and they share the same lifecycle.
* @param readSize Indicates the pointer to the size of the data read.
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
*
@@ -173,6 +311,17 @@ bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value);
*/
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize);
/**
* @brief Reads unpadded data from a <b>SBuf</b>.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param length Indicates the length of the data to read.
* @return Returns the pointer to the unpadded data if the operation is successful; returns a null pointer otherwise.
*
* @since 1.0
*/
const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length);
/**
* @brief Reads a 64-bit unsigned integer from a <b>SBuf</b>.
*
@@ -273,10 +422,11 @@ bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value);
const char *HdfSbufReadString(struct HdfSBuf *sbuf);
/**
* @brief Obtains the pointer to the data stored in a<b>SBuf</b>.
* @brief Obtains the pointer to the data stored in a <b>SBuf</b>.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @return Returns the pointer to the data stored in the target <b>SBuf</b>.
* @return Returns the pointer to the data stored in the target <b>SBuf</b> if the operation is successful;
* returns a null pointer otherwise.
*
* @since 1.0
*/
@@ -296,6 +446,7 @@ void HdfSbufFlush(struct HdfSBuf *sbuf);
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @return Returns the <b>SBuf</b> capacity.
*
* @since 1.0
*/
size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf);
@@ -310,10 +461,20 @@ size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf);
*/
size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf);
/**
* @brief Sets the data size of a <b>SBuf</b>.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @param size Indicates the data size to set, which cannot exceed the size obtained via {@link HdfSbufGetDataSize}.
*
* @since 1.0
*/
void HdfSbufSetDataSize(struct HdfSBuf *sbuf, size_t size);
/**
* @brief Obtains a <b>SBuf</b> instance.
*
* @param capacity Indicates the initial capacity of the<b>SBuf</b>.
* @param capacity Indicates the initial capacity of the <b>SBuf</b>.
* @return Returns the <b>SBuf</b> instance.
*
* @since 1.0
@@ -343,9 +504,9 @@ struct HdfSBuf *HdfSBufObtainDefaultSize(void);
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size);
/**
* @brief Releases a <b>SBuf </b>.
* @brief Releases a <b>SBuf</b>.
*
* @param sbuf Indicates the pointer to the <b>SBuf</b> to release.
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
*
* @since 1.0
*/
@@ -383,6 +544,62 @@ struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf);
*/
void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf);
/**
* @brief Obtains a <b>SBuf</b> instance of a specified type.
*
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
* @return Returns the <b>SBuf</b> instance.
*
* @since 1.0
*/
struct HdfSBuf *HdfSBufTypedObtain(uint32_t type);
/**
* @brief Obtains a <b>SBuf</b> instance of a specified type based on the implementation of an existing <b>SBuf</b>.
*
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
* @param impl Indicates the pointer to the implementation of an existing <b>SBuf</b>.
* @return Returns the new <b>SBuf</b> instance.
*
* @since 1.0
*/
struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl);
/**
* @brief Obtains a <b>SBuf</b> instance of a specified type with the given initial capacity.
*
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
* @param capacity Indicates the initial capacity of the <b>SBuf</b>.
* @return Returns the new <b>SBuf</b> instance.
*
* @since 1.0
*/
struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity);
/**
* @brief Creates a <b>SBuf</b> instance of a specified type with the specified data and size.
* The pointer to the data stored in the <b>SBuf</b> is released by the caller,
* and the written data size should not exceed the specified value of <b>size</b>.
*
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
* @param base Indicates the base of the data to use.
* @param size Indicates the size of the data to use.
* @return Returns the <b>SBuf</b> instance.
*
* @since 1.0
*/
struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size);
/**
* @brief Obtains the implementation of a <b>SBuf</b>.
*
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
* @return Returns the pointer to the implementation of the <b>SBuf</b>.
*
* @since 1.0
*/
struct HdfSbufImpl *HdfSbufGetImpl(struct HdfSBuf *sbuf);
#ifdef __cplusplus
}
#endif /* __cplusplus */
+74
View File
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_SBU_IMPL_H
#define HDF_SBU_IMPL_H
#include "hdf_base.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct HdfSbufConstructor {
struct HdfSbufImpl *(*obtain)(size_t capacity);
struct HdfSbufImpl *(*bind)(uintptr_t base, size_t size);
};
struct HdfRemoteService;
struct HdfSbufImpl {
bool (*writeBuffer)(struct HdfSbufImpl *sbuf, const uint8_t *data, uint32_t writeSize);
bool (*writeUnpadBuffer)(struct HdfSbufImpl *sbuf, const uint8_t *data, uint32_t writeSize);
bool (*writeUint64)(struct HdfSbufImpl *sbuf, uint64_t value);
bool (*writeUint32)(struct HdfSbufImpl *sbuf, uint32_t value);
bool (*writeUint16)(struct HdfSbufImpl *sbuf, uint16_t value);
bool (*writeUint8)(struct HdfSbufImpl *sbuf, uint8_t value);
bool (*writeInt64)(struct HdfSbufImpl *sbuf, int64_t value);
bool (*writeInt32)(struct HdfSbufImpl *sbuf, int32_t value);
bool (*writeInt16)(struct HdfSbufImpl *sbuf, int16_t value);
bool (*writeInt8)(struct HdfSbufImpl *sbuf, int8_t value);
bool (*writeString)(struct HdfSbufImpl *sbuf, const char *value);
bool (*writeFileDescriptor)(struct HdfSbufImpl *sbuf, int fd);
bool (*writeFloat)(struct HdfSbufImpl *sbuf, float value);
bool (*writeDouble)(struct HdfSbufImpl *sbuf, double value);
bool (*readDouble)(struct HdfSbufImpl *sbuf, double *value);
bool (*readFloat)(struct HdfSbufImpl *sbuf, float *value);
int (*readFileDescriptor)(struct HdfSbufImpl *sbuf);
bool (*writeString16)(struct HdfSbufImpl *sbuf, const char16_t *value, uint32_t size);
bool (*readBuffer)(struct HdfSbufImpl *sbuf, const uint8_t **data, uint32_t *readSize);
const uint8_t *(*readUnpadBuffer)(struct HdfSbufImpl *sbuf, size_t length);
bool (*readUint64)(struct HdfSbufImpl *sbuf, uint64_t *value);
bool (*readUint32)(struct HdfSbufImpl *sbuf, uint32_t *value);
bool (*readUint16)(struct HdfSbufImpl *sbuf, uint16_t *value);
bool (*readUint8)(struct HdfSbufImpl *sbuf, uint8_t *value);
bool (*readInt64)(struct HdfSbufImpl *sbuf, int64_t *value);
bool (*readInt32)(struct HdfSbufImpl *sbuf, int32_t *value);
bool (*readInt16)(struct HdfSbufImpl *sbuf, int16_t *value);
bool (*readInt8)(struct HdfSbufImpl *sbuf, int8_t *value);
const char *(*readString)(struct HdfSbufImpl *sbuf);
const char16_t *(*readString16)(struct HdfSbufImpl *sbuf);
int32_t (*writeRemoteService)(struct HdfSbufImpl *sbuf, const struct HdfRemoteService *service);
struct HdfRemoteService *(*readRemoteService)(struct HdfSbufImpl *sbuf);
const uint8_t *(*getData)(const struct HdfSbufImpl *sbuf);
void (*flush)(struct HdfSbufImpl *sbuf);
size_t (*getCapacity)(const struct HdfSbufImpl *sbuf);
size_t (*getDataSize)(const struct HdfSbufImpl *sbuf);
void (*setDataSize)(struct HdfSbufImpl *sbuf, size_t size);
void (*recycle)(struct HdfSbufImpl *sbuf);
struct HdfSbufImpl *(*move)(struct HdfSbufImpl *sbuf);
struct HdfSbufImpl *(*copy)(const struct HdfSbufImpl *sbuf);
void (*transDataOwnership)(struct HdfSbufImpl *sbuf);
};
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* HDF_SBUF_H */
/** @} */
+296 -304
View File
@@ -6,459 +6,451 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "securec.h"
#include "osal_mem.h"
#include "hdf_log.h"
#include "hdf_sbuf.h"
#include "hdf_log.h"
#include "hdf_sbuf_impl.h"
#include "osal_mem.h"
#define HDF_SBUF_GROW_SIZE_DEFAULT 256
#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512kB
#define HDF_SBUF_ALIGN 4
#define HDF_SBUF_DEFAULT_SIZE 256
#define HDF_SBUF_IMPL_CHECK_RETURN(sbuf, api, retCode) \
do { \
if (sbuf == NULL || sbuf->impl == NULL) { \
HDF_LOGE("%s: invalid sbuf object", __func__); \
return retCode; \
} \
if (sbuf->impl->api == NULL) { \
HDF_LOGE(#api " is not support on %d sbuf", sbuf->type); \
return retCode; \
} \
} while (0)
#ifndef INT16_MAX
#ifdef S16_MAX
#define INT16_MAX S16_MAX
#else
#define INT16_MAX 32767
#endif // !S16_MAX
#endif // INT16_MAX
#define HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, api) \
do { \
if (sbuf == NULL || sbuf->impl == NULL) { \
HDF_LOGE("%s: invalid sbuf object", __func__); \
return; \
} \
if (sbuf->impl->api == NULL) { \
HDF_LOGE(#api " is not support on %d sbuf", sbuf->type); \
return; \
} \
} while (0)
static inline size_t HdfSbufGetAlignSize(size_t size)
struct HdfSBuf {
struct HdfSbufImpl *impl;
uint32_t type;
};
struct HdfSbufImpl *SbufObtainRaw(size_t capacity);
struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size);
struct HdfSbufImpl *SbufObtainIpc(size_t capacity) __attribute__((weak));
struct HdfSbufImpl *SbufBindIpc(uintptr_t base, size_t size) __attribute__((weak));
struct HdfSbufImpl *SbufObtainIpcHw(size_t capacity) __attribute__((weak));
struct HdfSbufImpl *SbufBindRawIpcHw(uintptr_t base, size_t size) __attribute__((weak));
static const struct HdfSbufConstructor g_sbufConstructorMap[SBUF_TYPE_MAX] = {
[SBUF_RAW] = {
.obtain = SbufObtainRaw,
.bind = SbufBindRaw,
},
[SBUF_IPC] = {
.obtain = SbufObtainIpc,
.bind = SbufBindIpc,
},
[SBUF_IPC_HW] = {
.obtain = SbufObtainIpcHw,
.bind = SbufBindRawIpcHw,
},
};
static const struct HdfSbufConstructor *HdfSbufConstructorGet(uint32_t type)
{
return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1));
}
static size_t HdfSbufGetLeftWriteSize(struct HdfSBuf *sbuf)
{
return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos);
}
static size_t HdfSbufGetLeftReadSize(struct HdfSBuf *sbuf)
{
return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos);
}
static bool HdfSbufWriteRollback(struct HdfSBuf *sbuf, uint32_t size)
{
size_t alignSize = HdfSbufGetAlignSize(size);
if (sbuf->writePos < alignSize) {
return false;
if (type >= SBUF_TYPE_MAX) {
return NULL;
}
sbuf->writePos -= alignSize;
return true;
}
static bool HdfSbufReadRollback(struct HdfSBuf *sbuf, uint32_t size)
{
size_t alignSize = HdfSbufGetAlignSize(size);
if (sbuf->readPos < alignSize) {
return false;
}
sbuf->readPos -= alignSize;
return true;
return &g_sbufConstructorMap[type];
}
uint8_t *HdfSbufGetData(const struct HdfSBuf *sbuf)
{
if (sbuf == NULL) {
HDF_LOGE("Get data is null, input sbuf is null");
return NULL;
}
return (uint8_t *)sbuf->data;
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getData, NULL);
return (uint8_t *)sbuf->impl->getData(sbuf->impl);
}
void HdfSbufFlush(struct HdfSBuf *sbuf)
{
if (sbuf != NULL) {
sbuf->readPos = 0;
sbuf->writePos = 0;
}
HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, getData);
sbuf->impl->flush(sbuf->impl);
}
size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf)
{
return (sbuf != NULL) ? sbuf->capacity : 0;
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getCapacity, HDF_FAILURE);
return (sbuf != NULL && sbuf->impl != NULL) ? sbuf->impl->getCapacity(sbuf->impl) : 0;
}
size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf)
{
return (sbuf != NULL) ? sbuf->writePos : 0;
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getDataSize, HDF_FAILURE);
return sbuf->impl->getDataSize(sbuf->impl);
}
static bool HdfSbufGrow(struct HdfSBuf *sbuf, uint32_t growSize)
void HdfSbufSetDataSize(struct HdfSBuf *sbuf, size_t size)
{
if (sbuf->isBind) {
HDF_LOGE("%s: binded sbuf oom", __func__);
return false;
}
uint32_t newSize = HdfSbufGetAlignSize(sbuf->capacity + growSize);
if (newSize < sbuf->capacity) {
HDF_LOGE("%s: grow size overflow", __func__);
return false;
}
if (newSize > HDF_SBUF_MAX_SIZE) {
HDF_LOGE("%s: buf size over limit", __func__);
return false;
}
uint8_t *newData = OsalMemCalloc(newSize);
if (newData == NULL) {
HDF_LOGE("%s: oom", __func__);
return false;
}
if (sbuf->data != NULL) {
if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
OsalMemFree(newData);
return false;
}
OsalMemFree(sbuf->data);
}
sbuf->data = newData;
sbuf->capacity = newSize;
return true;
}
static bool HdfSbufWrite(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t size)
{
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
return false;
}
if (size == 0) {
return true;
}
size_t alignSize = HdfSbufGetAlignSize(size);
// in case of desireCapacity overflow
if (alignSize < size) {
HDF_LOGE("desireCapacity is overflow");
return false;
}
size_t writeableSize = HdfSbufGetLeftWriteSize(sbuf);
if (alignSize > writeableSize) {
size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT) :
HDF_SBUF_GROW_SIZE_DEFAULT;
if (!HdfSbufGrow(sbuf, growSize)) {
return false;
}
writeableSize = HdfSbufGetLeftWriteSize(sbuf);
}
uint8_t *dest = sbuf->data + sbuf->writePos;
if (memcpy_s(dest, writeableSize, data, size) != EOK) {
return false; /* never hits */
}
sbuf->writePos += alignSize;
return true;
}
static bool HdfSbufRead(struct HdfSBuf *sbuf, uint8_t *data, uint32_t readSize)
{
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
return false;
}
if (readSize == 0) {
return true;
}
size_t alignSize = HdfSbufGetAlignSize(readSize);
if (alignSize > HdfSbufGetLeftReadSize(sbuf)) {
HDF_LOGE("Read out of buffer range");
return false;
}
if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) {
return false; // never hits
}
sbuf->readPos += alignSize;
return true;
HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, setDataSize);
sbuf->impl->setDataSize(sbuf->impl, size);
}
bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize)
{
if (sbuf == NULL) {
HDF_LOGE("Write buffer failed, input param is invalid");
return false;
}
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getCapacity, false);
return sbuf->impl->writeBuffer(sbuf->impl, (const uint8_t *)data, writeSize);
}
bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t writeSize)
{
if (data == NULL) {
return HdfSbufWriteInt32(sbuf, 0);
}
if (!HdfSbufWriteInt32(sbuf, writeSize)) {
return false;
}
if (!HdfSbufWrite(sbuf, data, writeSize)) {
(void)HdfSbufWriteRollback(sbuf, sizeof(int32_t));
return false;
}
return true;
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUnpadBuffer, false);
return sbuf->impl->writeUnpadBuffer(sbuf->impl, data, writeSize);
}
const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUnpadBuffer, false);
return sbuf->impl->readUnpadBuffer(sbuf->impl, length);
}
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize)
{
if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) {
HDF_LOGE("%s:input invalid", __func__);
return false;
}
int buffSize = 0;
if (!HdfSbufReadInt32(sbuf, &buffSize)) {
return false;
}
if (buffSize == 0) {
*data = NULL;
*readSize = 0;
return true;
}
size_t alignSize = HdfSbufGetAlignSize(buffSize);
if (alignSize > HdfSbufGetLeftReadSize(sbuf)) {
HDF_LOGE("%s:readBuff out of range", __func__);
(void)HdfSbufReadRollback(sbuf, sizeof(int32_t));
return false;
}
*data = sbuf->data + sbuf->readPos;
*readSize = buffSize;
sbuf->readPos += alignSize;
return true;
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readBuffer, false);
return sbuf->impl->readBuffer(sbuf->impl, (const uint8_t **)data, readSize);
}
bool HdfSbufWriteUint64(struct HdfSBuf *sbuf, uint64_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint64, false);
return sbuf->impl->writeUint64(sbuf->impl, value);
}
bool HdfSbufWriteUint32(struct HdfSBuf *sbuf, uint32_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint32, false);
return sbuf->impl->writeUint32(sbuf->impl, value);
}
bool HdfSbufWriteUint16(struct HdfSBuf *sbuf, uint16_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint16, false);
return sbuf->impl->writeUint16(sbuf->impl, value);
}
bool HdfSbufWriteUint8(struct HdfSBuf *sbuf, uint8_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint8, false);
return sbuf->impl->writeUint8(sbuf->impl, value);
}
bool HdfSbufWriteInt64(struct HdfSBuf *sbuf, int64_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt64, false);
return sbuf->impl->writeInt64(sbuf->impl, value);
}
bool HdfSbufWriteInt32(struct HdfSBuf *sbuf, int32_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt32, false);
return sbuf->impl->writeInt32(sbuf->impl, value);
}
bool HdfSbufWriteInt16(struct HdfSBuf *sbuf, int16_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt16, false);
return sbuf->impl->writeInt16(sbuf->impl, value);
}
bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value)
{
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt8, false);
return sbuf->impl->writeInt8(sbuf->impl, value);
}
bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value)
{
if (sbuf == NULL) {
HDF_LOGE("%s:input null", __func__);
return false;
}
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString, false);
return sbuf->impl->writeString(sbuf->impl, value);
}
return HdfSbufWriteBuffer(sbuf, value, value ? (strlen(value) + 1) : 0);
bool HdfSbufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString16, false);
return sbuf->impl->writeString16(sbuf->impl, value, size);
}
bool HdfSbufReadUint64(struct HdfSBuf *sbuf, uint64_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint64, false);
return sbuf->impl->readUint64(sbuf->impl, value);
}
bool HdfSbufReadUint32(struct HdfSBuf *sbuf, uint32_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint32, false);
return sbuf->impl->readUint32(sbuf->impl, value);
}
bool HdfSbufReadUint16(struct HdfSBuf *sbuf, uint16_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint16, false);
return sbuf->impl->readUint16(sbuf->impl, value);
}
bool HdfSbufReadUint8(struct HdfSBuf *sbuf, uint8_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint8, false);
return sbuf->impl->readUint8(sbuf->impl, value);
}
bool HdfSbufReadInt64(struct HdfSBuf *sbuf, int64_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt64, false);
return sbuf->impl->readInt64(sbuf->impl, value);
}
bool HdfSbufReadInt32(struct HdfSBuf *sbuf, int32_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt32, false);
return sbuf->impl->readInt32(sbuf->impl, value);
}
bool HdfSbufReadInt16(struct HdfSBuf *sbuf, int16_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt16, false);
return sbuf->impl->readInt16(sbuf->impl, value);
}
bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value)
{
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt8, false);
return sbuf->impl->readInt8(sbuf->impl, value);
}
const char *HdfSbufReadString(struct HdfSBuf *sbuf)
{
if (sbuf == NULL || sbuf->data == NULL) {
HDF_LOGE("%s:input null", __func__);
return NULL;
}
/* this length contains '\0' at the end. */
int32_t strLen = 0;
if (!HdfSbufReadInt32(sbuf, &strLen) || strLen <= 0) {
return NULL;
}
size_t alignSize = HdfSbufGetAlignSize(strLen);
if (strLen > INT16_MAX || alignSize > HdfSbufGetLeftReadSize(sbuf)) {
(void)HdfSbufReadRollback(sbuf, sizeof(int32_t));
return NULL;
}
char *str = (char *)(sbuf->data + sbuf->readPos);
sbuf->readPos += alignSize;
/* force set '\0' at end of the string */
str[strLen - 1] = '\0';
return str;
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString, false);
return sbuf->impl->readString(sbuf->impl);
}
struct HdfSBuf *HdfSBufObtainDefaultSize()
bool HdfSBufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size)
{
return HdfSBufObtain(HDF_SBUF_GROW_SIZE_DEFAULT);
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString16, false);
return sbuf->impl->writeString16(sbuf->impl, value, size);
}
const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString16, false);
return sbuf->impl->readString16(sbuf->impl);
}
int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteService *service)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeRemoteService, false);
return sbuf->impl->writeRemoteService(sbuf->impl, service);
}
struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readRemoteService, false);
return sbuf->impl->readRemoteService(sbuf->impl);
}
bool HdfSbufWriteFloat(struct HdfSBuf *sbuf, float data)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeFloat, false);
return sbuf->impl->writeFloat(sbuf->impl, data);
}
bool HdfSbufWriteDouble(struct HdfSBuf *sbuf, double data)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeDouble, false);
return sbuf->impl->writeDouble(sbuf->impl, data);
}
bool HdfSbufWriteFileDescriptor(struct HdfSBuf *sbuf, int fd)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeFileDescriptor, false);
return sbuf->impl->writeFileDescriptor(sbuf->impl, fd);
}
int HdfSbufReadFileDescriptor(struct HdfSBuf *sbuf)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readFileDescriptor, false);
return sbuf->impl->readFileDescriptor(sbuf->impl);
}
bool HdfSbufReadDouble(struct HdfSBuf *sbuf, double *data)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readDouble, false);
return sbuf->impl->readDouble(sbuf->impl, data);
}
bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *data)
{
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readFloat, false);
return sbuf->impl->readFloat(sbuf->impl, data);
}
struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity)
{
const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type);
if (constructor == NULL) {
HDF_LOGE("sbuf constructor %d not implement", type);
return NULL;
}
if (constructor->obtain == NULL) {
HDF_LOGE("sbuf constructor %d obtain method not implement", type);
return NULL;
}
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (sbuf == NULL) {
HDF_LOGE("instance sbuf failure");
return NULL;
}
sbuf->impl = constructor->obtain(capacity);
if (sbuf->impl == NULL) {
OsalMemFree(sbuf);
HDF_LOGE("sbuf obtain fail, size=%u", (uint32_t)capacity);
return NULL;
}
sbuf->type = type;
return sbuf;
}
struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl)
{
if (type >= SBUF_TYPE_MAX || impl == NULL) {
return NULL;
}
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (sbuf == NULL) {
HDF_LOGE("obtain in-place sbuf failure");
return NULL;
}
sbuf->impl = impl;
sbuf->type = type;
return sbuf;
}
struct HdfSBuf *HdfSBufTypedObtain(uint32_t type)
{
return HdfSBufTypedObtainCapacity(type, HDF_SBUF_DEFAULT_SIZE);
}
struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size)
{
const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type);
if (constructor == NULL) {
HDF_LOGE("sbuf constructor %d not implement", type);
return NULL;
}
if (constructor->bind == NULL) {
HDF_LOGE("sbuf constructor %d bind method not implement", type);
return NULL;
}
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (sbuf == NULL) {
HDF_LOGE("instance sbuf failure");
return NULL;
}
sbuf->impl = constructor->bind(base, size);
if (sbuf->impl == NULL) {
OsalMemFree(sbuf);
HDF_LOGE("sbuf bind fail");
return NULL;
}
sbuf->type = type;
return sbuf;
}
struct HdfSBuf *HdfSBufObtain(size_t capacity)
{
if (capacity > HDF_SBUF_MAX_SIZE) {
HDF_LOGE("%s: buf size over limit", __func__);
return NULL;
}
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (sbuf == NULL) {
HDF_LOGE("instance usbuf failure");
return NULL;
}
return HdfSBufTypedObtainCapacity(SBUF_RAW, capacity);
}
sbuf->data = (uint8_t *)OsalMemCalloc(capacity);
if (sbuf->data == NULL) {
OsalMemFree(sbuf);
HDF_LOGE("sbuf obtain oom, size=%u", (uint32_t)capacity);
return NULL;
}
sbuf->capacity = capacity;
sbuf->writePos = 0;
sbuf->readPos = 0;
sbuf->isBind = false;
return sbuf;
struct HdfSBuf *HdfSBufObtainDefaultSize()
{
return HdfSBufObtain(HDF_SBUF_DEFAULT_SIZE);
}
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size)
{
if (base == 0 || size == 0) {
return NULL;
}
/* require 4 byte alignment for base */
if ((base & 0x3) != 0) {
HDF_LOGE("Base is not align for 4-byte");
return NULL;
}
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (sbuf == NULL) {
HDF_LOGE("%s: oom", __func__);
return NULL;
}
sbuf->data = (uint8_t *)base;
sbuf->capacity = size;
sbuf->writePos = size;
sbuf->readPos = 0;
sbuf->isBind = true;
return sbuf;
return HdfSBufTypedBind(SBUF_RAW, base, size);
}
struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf)
{
if (sbuf == NULL || sbuf->data == NULL) {
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, copy, NULL);
struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (newBuf == NULL) {
return NULL;
}
struct HdfSBuf *new = HdfSBufObtain(sbuf->capacity);
if (new == NULL) {
newBuf->impl = sbuf->impl->copy(sbuf->impl);
if (newBuf->impl == NULL) {
OsalMemFree(newBuf);
return NULL;
}
new->capacity = sbuf->capacity;
new->readPos = 0;
new->writePos = sbuf->writePos;
if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->writePos) != EOK) {
HdfSBufRecycle(new);
return NULL;
}
return new;
newBuf->type = sbuf->type;
return newBuf;
}
struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf)
{
if (sbuf == NULL || sbuf->isBind) {
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, move, NULL);
struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
if (newBuf == NULL) {
return NULL;
}
struct HdfSBuf *new = OsalMemCalloc(sizeof(struct HdfSBuf));
if (new == NULL) {
newBuf->impl = sbuf->impl->move(sbuf->impl);
if (newBuf->impl == NULL) {
OsalMemFree(newBuf);
return NULL;
}
new->capacity = sbuf->capacity;
new->readPos = 0;
new->writePos = sbuf->writePos;
new->data = sbuf->data;
sbuf->data = NULL;
sbuf->capacity = 0;
HdfSbufFlush(sbuf);
return new;
return newBuf;
}
void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf)
{
if (sbuf == NULL) {
return;
}
sbuf->isBind = false;
HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, transDataOwnership);
sbuf->impl->transDataOwnership(sbuf->impl);
}
void HdfSBufRecycle(struct HdfSBuf *sbuf)
{
if (sbuf != NULL) {
if (sbuf->data != NULL && !sbuf->isBind) {
OsalMemFree(sbuf->data);
if (sbuf->impl != NULL && sbuf->impl->recycle != NULL) {
sbuf->impl->recycle(sbuf->impl);
sbuf->impl = NULL;
}
OsalMemFree(sbuf);
}
}
struct HdfSbufImpl *HdfSbufGetImpl(struct HdfSBuf *sbuf)
{
if (sbuf != NULL) {
return sbuf->impl;
}
return NULL;
}
+553
View File
@@ -0,0 +1,553 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_log.h"
#include "hdf_sbuf.h"
#include "hdf_sbuf_impl.h"
#include "osal_mem.h"
#include "securec.h"
#define HDF_SBUF_GROW_SIZE_DEFAULT 256
#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512KB
#define HDF_SBUF_ALIGN 4
#ifndef INT16_MAX
#ifdef S16_MAX
#define INT16_MAX S16_MAX
#else
#define INT16_MAX 32767
#endif // !S16_MAX
#endif // INT16_MAX
struct HdfSBufRaw {
struct HdfSbufImpl infImpl;
size_t writePos; /**< Current write position */
size_t readPos; /**< Current read position */
size_t capacity; /**< Storage capacity, 512 KB at most. */
uint8_t *data; /**< Pointer to data storage */
bool isBind; /**< Whether to bind the externally transferred pointer to data storage */
};
#define SBUF_RAW_CAST(impl) (struct HdfSBufRaw *)(impl)
static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity);
static void SbufInterfaceAssign(struct HdfSbufImpl *inf);
static size_t SbufRawImplGetAlignSize(size_t size)
{
return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1));
}
static void SbufRawImplRecycle(struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf != NULL) {
if (sbuf->data != NULL && !sbuf->isBind) {
OsalMemFree(sbuf->data);
}
OsalMemFree(sbuf);
}
}
static size_t SbufRawImplGetLeftWriteSize(struct HdfSBufRaw *sbuf)
{
return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos);
}
static size_t SbufRawImplGetLeftReadSize(struct HdfSBufRaw *sbuf)
{
return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos);
}
static bool SbufRawImplWriteRollback(struct HdfSbufImpl *impl, uint32_t size)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL) {
return false;
}
size_t alignSize = SbufRawImplGetAlignSize(size);
if (sbuf->writePos < alignSize) {
return false;
}
sbuf->writePos -= alignSize;
return true;
}
static bool SbufRawImplReadRollback(struct HdfSbufImpl *impl, uint32_t size)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL) {
return false;
}
size_t alignSize = SbufRawImplGetAlignSize(size);
if (sbuf->readPos < alignSize) {
return false;
}
sbuf->readPos -= alignSize;
return true;
}
static const uint8_t *SbufRawImplGetData(const struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL) {
HDF_LOGE("The obtained data is null, and the input Sbuf is null.");
return NULL;
}
return (uint8_t *)sbuf->data;
}
static void SbufRawImplSetDataSize(struct HdfSbufImpl *impl, size_t size)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL) {
return;
}
if (size <= sbuf->capacity) {
sbuf->readPos = 0;
sbuf->writePos = size;
}
}
static void SbufRawImplFlush(struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf != NULL) {
sbuf->readPos = 0;
sbuf->writePos = 0;
}
}
static size_t SbufRawImplGetCapacity(const struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
return (sbuf != NULL) ? sbuf->capacity : 0;
}
static size_t SbufRawImplGetDataSize(const struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
return (sbuf != NULL) ? sbuf->writePos : 0;
}
static bool SbufRawImplGrow(struct HdfSBufRaw *sbuf, uint32_t growSize)
{
if (sbuf->isBind) {
HDF_LOGE("%s: binded sbuf oom", __func__);
return false;
}
uint32_t newSize = SbufRawImplGetAlignSize(sbuf->capacity + growSize);
if (newSize < sbuf->capacity) {
HDF_LOGE("%s: grow size overflow", __func__);
return false;
}
if (newSize > HDF_SBUF_MAX_SIZE) {
HDF_LOGE("%s: buf size over limit", __func__);
return false;
}
uint8_t *newData = OsalMemCalloc(newSize);
if (newData == NULL) {
HDF_LOGE("%s: oom", __func__);
return false;
}
if (sbuf->data != NULL) {
if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
OsalMemFree(newData);
return false;
}
OsalMemFree(sbuf->data);
}
sbuf->data = newData;
sbuf->capacity = newSize;
return true;
}
static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t size)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
return false;
}
if (size == 0) {
return true;
}
size_t alignSize = SbufRawImplGetAlignSize(size);
// in case of desireCapacity overflow
if (alignSize < size) {
HDF_LOGE("desireCapacity overflow");
return false;
}
size_t writeableSize = SbufRawImplGetLeftWriteSize(sbuf);
if (alignSize > writeableSize) {
size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT)
: HDF_SBUF_GROW_SIZE_DEFAULT;
if (!SbufRawImplGrow(sbuf, growSize)) {
return false;
}
writeableSize = SbufRawImplGetLeftWriteSize(sbuf);
}
uint8_t *dest = sbuf->data + sbuf->writePos;
if (memcpy_s(dest, writeableSize, data, size) != EOK) {
return false; /* never hits */
}
sbuf->writePos += alignSize;
return true;
}
static bool SbufRawImplRead(struct HdfSbufImpl *impl, uint8_t *data, uint32_t readSize)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
return false;
}
if (readSize == 0) {
return true;
}
size_t alignSize = SbufRawImplGetAlignSize(readSize);
if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
HDF_LOGE("Read out of buffer range");
return false;
}
if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) {
return false; // never hit
}
sbuf->readPos += alignSize;
return true;
}
static bool SbufRawImplWriteUint64(struct HdfSbufImpl *impl, uint64_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteUint32(struct HdfSbufImpl *impl, uint32_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteUint16(struct HdfSbufImpl *impl, uint16_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteUint8(struct HdfSbufImpl *impl, uint8_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteInt64(struct HdfSbufImpl *impl, int64_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteInt32(struct HdfSbufImpl *impl, int32_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteInt16(struct HdfSbufImpl *impl, int16_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteInt8(struct HdfSbufImpl *impl, int8_t value)
{
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
}
static bool SbufRawImplWriteBuffer(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t writeSize)
{
if (impl == NULL) {
HDF_LOGE("Failed to write the Sbuf, invalid input params");
return false;
}
if (data == NULL) {
return SbufRawImplWriteInt32(impl, 0);
}
if (!SbufRawImplWriteInt32(impl, writeSize)) {
return false;
}
if (!SbufRawImplWrite(impl, data, writeSize)) {
(void)SbufRawImplWriteRollback(impl, sizeof(int32_t));
return false;
}
return true;
}
static bool SbufRawImplWriteString(struct HdfSbufImpl *impl, const char *value)
{
if (impl == NULL) {
HDF_LOGE("%s: input null", __func__);
return false;
}
return SbufRawImplWriteBuffer(impl, (const uint8_t *)value, value ? (strlen(value) + 1) : 0);
}
static bool SbufRawImplReadUint64(struct HdfSbufImpl *impl, uint64_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadUint32(struct HdfSbufImpl *impl, uint32_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadUint16(struct HdfSbufImpl *impl, uint16_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadUint8(struct HdfSbufImpl *impl, uint8_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadInt64(struct HdfSbufImpl *impl, int64_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadInt32(struct HdfSbufImpl *impl, int32_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadInt16(struct HdfSbufImpl *impl, int16_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadInt8(struct HdfSbufImpl *impl, int8_t *value)
{
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
}
static bool SbufRawImplReadBuffer(struct HdfSbufImpl *impl, const uint8_t **data, uint32_t *readSize)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) {
HDF_LOGE("%s: input invalid", __func__);
return false;
}
int buffSize = 0;
if (!SbufRawImplReadInt32(impl, &buffSize)) {
return false;
}
if (buffSize == 0) {
*data = NULL;
*readSize = 0;
return true;
}
size_t alignSize = SbufRawImplGetAlignSize(buffSize);
if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
HDF_LOGE("%s:readBuff out of range", __func__);
(void)SbufRawImplReadRollback(impl, sizeof(int32_t));
return false;
}
*data = sbuf->data + sbuf->readPos;
*readSize = buffSize;
sbuf->readPos += alignSize;
return true;
}
static const char *SbufRawImplReadString(struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL || sbuf->data == NULL) {
HDF_LOGE("%s: input null", __func__);
return NULL;
}
/* This length contains the '\0' at the end of the string. */
int32_t strLen = 0;
if (!SbufRawImplReadInt32(impl, &strLen) || strLen <= 0) {
return NULL;
}
size_t alignSize = SbufRawImplGetAlignSize(strLen);
if (strLen > INT16_MAX || alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
(void)SbufRawImplReadRollback(impl, sizeof(int32_t));
return NULL;
}
char *str = (char *)(sbuf->data + sbuf->readPos);
sbuf->readPos += alignSize;
/* Set '\0' at end of the string forcibly. */
str[strLen - 1] = '\0';
return str;
}
static struct HdfSbufImpl *SbufRawImplCopy(const struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL || sbuf->data == NULL) {
return NULL;
}
struct HdfSBufRaw *new = SbufRawImplNewInstance(sbuf->capacity);
if (new == NULL) {
return NULL;
}
new->capacity = sbuf->capacity;
new->readPos = 0;
new->writePos = sbuf->writePos;
if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->capacity) != EOK) {
SbufRawImplRecycle(&new->infImpl);
return NULL;
}
return &new->infImpl;
}
static struct HdfSbufImpl *SbufRawImplMove(struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL || sbuf->isBind) {
return NULL;
}
struct HdfSBufRaw *new = OsalMemCalloc(sizeof(struct HdfSBufRaw));
if (new == NULL) {
return NULL;
}
new->capacity = sbuf->capacity;
new->readPos = 0;
new->writePos = sbuf->writePos;
new->data = sbuf->data;
sbuf->data = NULL;
sbuf->capacity = 0;
SbufRawImplFlush(&sbuf->infImpl);
SbufInterfaceAssign(&new->infImpl);
return &new->infImpl;
}
static void SbufRawImplTransDataOwnership(struct HdfSbufImpl *impl)
{
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
if (sbuf == NULL) {
return;
}
sbuf->isBind = false;
}
static void SbufInterfaceAssign(struct HdfSbufImpl *inf)
{
inf->writeBuffer = SbufRawImplWriteBuffer;
inf->writeUint64 = SbufRawImplWriteUint64;
inf->writeUint32 = SbufRawImplWriteUint32;
inf->writeUint16 = SbufRawImplWriteUint16;
inf->writeUint8 = SbufRawImplWriteUint8;
inf->writeInt64 = SbufRawImplWriteInt64;
inf->writeInt32 = SbufRawImplWriteInt32;
inf->writeInt16 = SbufRawImplWriteInt16;
inf->writeInt8 = SbufRawImplWriteInt8;
inf->writeString = SbufRawImplWriteString;
inf->readBuffer = SbufRawImplReadBuffer;
inf->readUint64 = SbufRawImplReadUint64;
inf->readUint32 = SbufRawImplReadUint32;
inf->readUint16 = SbufRawImplReadUint16;
inf->readUint8 = SbufRawImplReadUint8;
inf->readInt64 = SbufRawImplReadInt64;
inf->readInt32 = SbufRawImplReadInt32;
inf->readInt16 = SbufRawImplReadInt16;
inf->readInt8 = SbufRawImplReadInt8;
inf->readString = SbufRawImplReadString;
inf->getData = SbufRawImplGetData;
inf->flush = SbufRawImplFlush;
inf->getCapacity = SbufRawImplGetCapacity;
inf->getDataSize = SbufRawImplGetDataSize;
inf->setDataSize = SbufRawImplSetDataSize;
inf->recycle = SbufRawImplRecycle;
inf->move = SbufRawImplMove;
inf->copy = SbufRawImplCopy;
inf->transDataOwnership = SbufRawImplTransDataOwnership;
}
static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity)
{
if (capacity > HDF_SBUF_MAX_SIZE) {
HDF_LOGE("%s: Sbuf size exceeding max limit", __func__);
return NULL;
}
struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemCalloc(sizeof(struct HdfSBufRaw));
if (sbuf == NULL) {
HDF_LOGE("Sbuf instance failure");
return NULL;
}
sbuf->data = (uint8_t *)OsalMemCalloc(capacity);
if (sbuf->data == NULL) {
OsalMemFree(sbuf);
HDF_LOGE("sbuf obtain memory oom, size=%u", (uint32_t)capacity);
return NULL;
}
sbuf->capacity = capacity;
sbuf->writePos = 0;
sbuf->readPos = 0;
sbuf->isBind = false;
SbufInterfaceAssign(&sbuf->infImpl);
return sbuf;
}
struct HdfSbufImpl *SbufObtainRaw(size_t capacity)
{
struct HdfSBufRaw *sbuf = SbufRawImplNewInstance(capacity);
if (sbuf == NULL) {
return NULL;
}
return &sbuf->infImpl;
}
struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size)
{
if (base == 0 || size == 0) {
return NULL;
}
/* 4-byte alignment is required for base. */
if ((base & 0x3) != 0) {
HDF_LOGE("Base not in 4-byte alignment");
return NULL;
}
struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemAlloc(sizeof(struct HdfSBufRaw));
if (sbuf == NULL) {
HDF_LOGE("%s: oom", __func__);
return NULL;
}
sbuf->data = (uint8_t *)base;
sbuf->capacity = size;
sbuf->writePos = size;
sbuf->readPos = 0;
sbuf->isBind = true;
SbufInterfaceAssign(&sbuf->infImpl);
return &sbuf->infImpl;
}
@@ -34,8 +34,8 @@ struct HdfDevListenerThread {
struct pollfd *pfds;
uint16_t pfdSize;
bool pollChanged;
struct DListHead *listenerListPtr;
bool shouldStop;
struct DListHead *listenerListPtr;
uint8_t status;
};
@@ -20,23 +20,23 @@ int32_t HdfLoadDriverByServiceName(const char *serviceName)
}
struct HdfIoService *ioService = HdfIoServiceBind(DEV_MGR_NODE);
if (ioService == NULL) {
HDF_LOGE("Fail to get %s service", DEV_MGR_NODE);
HDF_LOGE("failed to get %s service", DEV_MGR_NODE);
return ret;
}
data = HdfSBufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("fail to obtain sbuf data");
HDF_LOGE("failed to obtain sbuf data");
ret = HDF_DEV_ERR_NO_MEMORY;
goto out;
}
if (!HdfSbufWriteString(data, serviceName)) {
HDF_LOGE("fail to write sbuf");
HDF_LOGE("failed to write sbuf");
ret = HDF_FAILURE;
goto out;
}
ret = ioService->dispatcher->Dispatch(&ioService->object, DEVMGR_LOAD_SERVICE, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("fail to send service call");
HDF_LOGE("failed to load khdf driver %s", serviceName);
}
out:
HdfIoServiceRecycle(ioService);
@@ -54,23 +54,23 @@ int32_t HdfGetServiceNameByDeviceClass(DeviceClass deviceClass, struct HdfSBuf *
}
struct HdfIoService *ioService = HdfIoServiceBind(DEV_MGR_NODE);
if (ioService == NULL) {
HDF_LOGE("Fail to get %s service", DEV_MGR_NODE);
HDF_LOGE("failed to get %s service", DEV_MGR_NODE);
return ret;
}
data = HdfSBufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("fail to obtain sbuf data");
HDF_LOGE("failed to obtain sbuf data");
ret = HDF_DEV_ERR_NO_MEMORY;
goto out;
}
if (!HdfSbufWriteInt32(data, deviceClass)) {
HDF_LOGE("fail to write sbuf");
HDF_LOGE("failed to write sbuf");
ret = HDF_FAILURE;
goto out;
}
ret = ioService->dispatcher->Dispatch(&ioService->object, DEVMGR_GET_SERVICE, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("fail to send service call");
HDF_LOGE("failed to query service by class");
}
out:
HdfIoServiceRecycle(ioService);
+68 -55
View File
@@ -95,7 +95,7 @@ static int32_t HdfDevEventDispatchLocked(const struct HdfDevListenerThread *thre
return HDF_DEV_ERR_NO_MEMORY;
}
/* dispatch event to SERVICE GROUP listener */
/* Dispatch events to the service group listener */
if (thread->listenerListPtr != NULL) {
DLIST_FOR_EACH_ENTRY(listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
if (listener->onReceive != NULL) {
@@ -103,21 +103,19 @@ static int32_t HdfDevEventDispatchLocked(const struct HdfDevListenerThread *thre
} else if (listener->callBack != NULL) {
(void)listener->callBack(listener->priv, bwr->cmdCode, sbuf);
}
HdfSbufFlush(sbuf);
sbuf->writePos = bwr->readConsumed;
HdfSbufSetDataSize(sbuf, bwr->readConsumed);
}
}
OsalMutexLock(&adapter->mutex);
/* dispatch event to SERVICE(SyscallAdapter) listener */
/* Dispatch events to the service (SyscallAdapter) listener */
DLIST_FOR_EACH_ENTRY(listener, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
if (listener->onReceive != NULL) {
(void)listener->onReceive(listener, &adapter->super, bwr->cmdCode, sbuf);
} else if (listener->callBack != NULL) {
(void)listener->callBack(listener->priv, bwr->cmdCode, sbuf);
}
HdfSbufFlush(sbuf);
sbuf->writePos = bwr->readConsumed;
HdfSbufSetDataSize(sbuf, bwr->readConsumed);
}
OsalMutexUnlock(&adapter->mutex);
@@ -131,20 +129,20 @@ static int32_t HdfDevEventReadAndDispatch(struct HdfDevListenerThread *thread, i
int32_t ret = HDF_SUCCESS;
bwr.readBuffer = (uintptr_t)OsalMemAlloc(HDF_DEFAULT_BWR_READ_SIZE);
bwr.cmdCode = -1;
bwr.readConsumed = 0;
bwr.readSize = HDF_DEFAULT_BWR_READ_SIZE;
if (bwr.readBuffer == (uintptr_t)NULL) {
HDF_LOGE("%s: oom", __func__);
return HDF_DEV_ERR_NO_MEMORY;
}
bwr.cmdCode = -1;
bwr.readConsumed = 0;
bwr.readSize = HDF_DEFAULT_BWR_READ_SIZE;
OsalMutexLock(&thread->mutex);
struct HdfSyscallAdapter *adapter = HdfFdToAdapterLocked(thread, fd);
if (adapter == NULL) {
HDF_LOGI("%s:adapter invalid\n", __func__);
OsalMSleep(1);
HDF_LOGI("%s: invalid adapter", __func__);
OsalMSleep(1); // yield to sync adapter list
goto finish;
}
@@ -156,7 +154,9 @@ static int32_t HdfDevEventReadAndDispatch(struct HdfDevListenerThread *thread, i
ret = errno;
if (ret == -HDF_DEV_ERR_NORANGE) {
if (HdfDevEventGrowReadBuffer(&bwr) == HDF_SUCCESS) {
continue; /* read buffer may not enough, grow read buffer and try again */
/* read buffer may not enough, grow read buffer and try again--The read buffere is insufficient.
Expand the buffer and try again. */
continue;
}
}
if (ret == -HDF_DEV_ERR_NODATA) {
@@ -209,14 +209,6 @@ static int32_t AssignPfds(struct HdfDevListenerThread *thread, struct pollfd **p
return pfdCount;
}
static void HdfDevListenerThreadFree(struct HdfDevListenerThread *thread)
{
OsalMutexDestroy(&thread->mutex);
OsalMemFree(thread->pfds);
OsalThreadDestroy(&thread->thread);
OsalMemFree(thread);
}
#define POLL_WAIT_TIME_MS 100
static int32_t HdfDevEventListenTask(void *para)
{
@@ -262,8 +254,11 @@ exit:
OsalMemFree(pfds);
if (thread->shouldStop) {
/* exit due to async exit call, should free thread struct */
HdfDevListenerThreadFree(thread);
/* Exit due to async call and free the thread struct. */
OsalMutexDestroy(&thread->mutex);
OsalThreadDestroy(&thread->thread);
OsalMemFree(thread->pfds);
OsalMemFree(thread);
}
return HDF_SUCCESS;
@@ -273,7 +268,7 @@ static int32_t HdfAdapterStartListenIoctl(int fd)
{
int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_START, 0);
if (ret) {
HDF_LOGE("%s: fail to tell drv(%d) start %d %s", __func__, fd, errno, strerror(errno));
HDF_LOGE("%s: failed to notify drv(%d) of start %d %s", __func__, fd, errno, strerror(errno));
return HDF_ERR_IO;
}
@@ -284,7 +279,7 @@ static int32_t HdfAdapterStopListenIoctl(int fd)
{
int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_STOP, 0);
if (ret) {
HDF_LOGE("%s: fail to tell drv stop %d %s", __func__, errno, strerror(errno));
HDF_LOGE("%s: failed to notify drv(%d) of stop %d %s", __func__, fd, errno, strerror(errno));
return HDF_ERR_IO;
}
@@ -295,7 +290,7 @@ static int32_t HdfAdapterExitListenIoctl(int fd)
{
int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_EXIT, 0);
if (ret) {
HDF_LOGE("%s: fail to tell drv report exit %d %s", __func__, errno, strerror(errno));
HDF_LOGE("%s: failed to notify drv(%d) of exit %d %s", __func__, fd, errno, strerror(errno));
return HDF_ERR_IO;
}
@@ -305,13 +300,13 @@ static int32_t HdfAdapterExitListenIoctl(int fd)
static int32_t HdfDevListenerThreadDoInit(struct HdfDevListenerThread *thread)
{
if (OsalMutexInit(&thread->mutex) != HDF_SUCCESS) {
HDF_LOGE("%s: fail to create thread lock", __func__);
HDF_LOGE("%s: failed to create thread lock", __func__);
return HDF_FAILURE;
}
int32_t ret = OsalThreadCreate(&thread->thread, HdfDevEventListenTask, thread);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail to create thread", __func__);
HDF_LOGE("%s: failed to create thread", __func__);
thread->status = LISTENER_UNINITED;
OsalMutexDestroy(&thread->mutex);
return HDF_ERR_THREAD_CREATE_FAIL;
@@ -499,7 +494,7 @@ static int32_t HdfIoServiceGroupThreadStart(struct HdfSyscallAdapterGroup *group
static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter)
{
/* if thread is not bind to service group, not need to do poll add */
/* If thread is not bound to a service group, you do not need to add a poll. */
if (thread->adapterListPtr == NULL) {
return HDF_SUCCESS;
}
@@ -529,7 +524,7 @@ static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struc
if (headAdapter != NULL) {
if (ioctl(headAdapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) {
HDF_LOGE("%s: fail to wakeup drv to add poll %d %s", __func__, errno, strerror(errno));
HDF_LOGE("%s: failed to wakeup drv to add poll %d %s", __func__, errno, strerror(errno));
thread->pfds[index].fd = SYSCALL_INVALID_FD;
ret = HDF_ERR_IO;
break;
@@ -568,11 +563,11 @@ static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct
}
if (HdfAdapterStopListenIoctl(adapter->fd)) {
HDF_LOGE("%s: fail to stop device report %d %s", __func__, errno, strerror(errno));
HDF_LOGE("%s: failed to stop device report %d %s", __func__, errno, strerror(errno));
}
if (ioctl(adapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) {
HDF_LOGE("%s: fail to wakeup drv to del poll %d %s", __func__, errno, strerror(errno));
HDF_LOGE("%s: failed to wakeup drv to del poll %d %s", __func__, errno, strerror(errno));
}
DListRemove(&adapter->listNode);
adapter->group = NULL;
@@ -580,6 +575,14 @@ static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct
OsalMutexUnlock(&thread->mutex);
}
static void HdfDevListenerThreadFree(struct HdfDevListenerThread *thread)
{
OsalMutexDestroy(&thread->mutex);
OsalMemFree(thread->pfds);
OsalThreadDestroy(&thread->thread);
OsalMemFree(thread);
}
static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread)
{
if (thread == NULL) {
@@ -648,10 +651,10 @@ static int32_t HdfSyscallAdapterDispatch(struct HdfObject *object, int32_t code,
wrBuf.cmdCode = code;
int32_t ret = ioctl(ioService->fd, HDF_WRITE_READ, &wrBuf);
if (ret < 0) {
HDF_LOGE("dispatch serv call ioctl fail %d", errno);
HDF_LOGE("Failed to dispatch serv call ioctl %d", errno);
}
if (reply != NULL) {
reply->writePos = wrBuf.readConsumed;
HdfSbufSetDataSize(reply, wrBuf.readConsumed);
}
return ret;
}
@@ -660,41 +663,48 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
{
struct HdfSyscallAdapter *adapter = NULL;
struct HdfIoService *ioService = NULL;
char devNodePath[PATH_MAX] = {0};
char realPath[PATH_MAX] = {0};
char *devNodePath = NULL;
char *realPath = NULL;
const char *devPath = DEV_NODE_PATH;
if (access(DEV_NODE_PATH, F_OK) != 0) {
devPath = DEV_PATH;
}
devNodePath = OsalMemCalloc(PATH_MAX);
realPath = OsalMemCalloc(PATH_MAX);
if (devNodePath == NULL || realPath == NULL) {
HDF_LOGE("%s: out of memory", __func__);
goto out;
}
if (sprintf_s(devNodePath, PATH_MAX - 1, "%s%s", devPath, serviceName) < 0) {
HDF_LOGE("Get node path failed");
return NULL;
HDF_LOGE("Failed to get the node path");
goto out;
}
if (realpath(devNodePath, realPath) == NULL) {
if (HdfLoadDriverByServiceName(serviceName) != HDF_SUCCESS) {
HDF_LOGE("%s load %s driver failed", __func__, serviceName);
return NULL;
HDF_LOGE("%s: load %s driver failed", __func__, serviceName);
goto out;
}
if (realpath(devNodePath, realPath) == NULL) {
HDF_LOGE("%s file name %s is invalid", __func__, devNodePath);
return NULL;
HDF_LOGE("%s: file name %s is invalid", __func__, devNodePath);
goto out;
}
}
adapter = (struct HdfSyscallAdapter *)OsalMemCalloc(sizeof(struct HdfSyscallAdapter));
if (adapter == NULL) {
HDF_LOGE("Alloc syscall adapter failed");
return NULL;
HDF_LOGE("Failed to allocate SyscallAdapter");
goto out;
}
DListHeadInit(&adapter->listenerList);
if (OsalMutexInit(&adapter->mutex)) {
HDF_LOGE("%s: create mutex fail", __func__);
HDF_LOGE("%s: Failed to create mutex", __func__);
OsalMemFree(adapter);
return NULL;
goto out;
}
adapter->fd = open(realPath, O_RDWR);
@@ -702,13 +712,16 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
HDF_LOGE("Open file node %s failed, (%d)%s", realPath, errno, strerror(errno));
OsalMutexDestroy(&adapter->mutex);
OsalMemFree(adapter);
return NULL;
goto out;
}
ioService = &adapter->super;
static struct HdfIoDispatcher dispatch = {
.Dispatch = HdfSyscallAdapterDispatch,
};
ioService->dispatcher = &dispatch;
out:
OsalMemFree(devNodePath);
OsalMemFree(realPath);
return ioService;
}
@@ -743,7 +756,7 @@ static int32_t HdfIoServiceThreadBindLocked(struct HdfSyscallAdapter *adapter)
static int32_t HdfIoServiceStartListen(struct HdfSyscallAdapter *adapter)
{
if (HdfIoServiceThreadBindLocked(adapter) != HDF_SUCCESS) {
HDF_LOGE("%s:adapter bind thread fail", __func__);
HDF_LOGE("%s: Failed to bind a thread to SyscallAdapter", __func__);
return HDF_FAILURE;
}
@@ -755,7 +768,7 @@ static bool AddListenerToAdapterLocked(struct HdfSyscallAdapter *adapter, struct
struct HdfDevEventlistener *it = NULL;
DLIST_FOR_EACH_ENTRY(it, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
if (it == listener) {
HDF_LOGE("add duplicate dev-event listener");
HDF_LOGE("Add a listener for duplicate dev-event");
return false;
}
}
@@ -770,7 +783,7 @@ int32_t HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDe
}
if (listener->callBack == NULL && listener->onReceive == NULL) {
HDF_LOGE("listenr onReceive func not implement");
HDF_LOGE("Listenr onReceive func not implemented");
return HDF_ERR_INVALID_OBJECT;
}
@@ -784,7 +797,7 @@ int32_t HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDe
}
if (adapter->group != NULL) {
/* service in group, should not bind to self hold thread and try to start group thread */
/* Do not bind any service in a service goup to its own thread or start the group thread. */
ret = HdfIoServiceGroupThreadStart(adapter->group);
OsalMutexUnlock(&adapter->mutex);
return ret;
@@ -806,7 +819,7 @@ int32_t HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct Hdf
}
if (listener->listNode.next == NULL || listener->listNode.prev == NULL) {
HDF_LOGE("%s:broken listener, may double unregister", __func__);
HDF_LOGE("%s: broken listener, may double unregister", __func__);
return HDF_ERR_INVALID_OBJECT;
}
@@ -872,7 +885,7 @@ int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struc
}
if (listener->callBack == NULL && listener->onReceive == NULL) {
HDF_LOGE("listenr onReceive func not implement");
HDF_LOGE("listenr onReceive func not implemented");
return HDF_ERR_INVALID_OBJECT;
}
struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
@@ -891,8 +904,8 @@ int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struc
struct HdfDevEventlistener *it = NULL;
DLIST_FOR_EACH_ENTRY(it, &adapterGroup->listenerList, struct HdfDevEventlistener, listNode) {
if (it == listener) {
HDF_LOGE("add group listener failed, repeated registration");
ret = HDF_ERR_INVALID_OBJECT;
HDF_LOGE("Failed to add group listener, repeated registration");
ret = HDF_ERR_INVALID_PARAM;
goto finish;
}
}
@@ -917,7 +930,7 @@ static int32_t GetListenerCount(struct HdfDevListenerThread *thread)
OsalMutexLock(&thread->mutex);
if (thread->listenerListPtr != NULL) {
DLIST_FOR_EACH_ENTRY (listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
DLIST_FOR_EACH_ENTRY(listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
count++;
}
}
+14 -15
View File
@@ -20,7 +20,7 @@
#define HDF_LOG_TAG hdf_vnode
#define VOID_DATA_SIZE 4
#define EVENT_QUEUE_MAX 100
#define MAX_RW_SIZE (1024*1204) // 1M
#define MAX_RW_SIZE (1024 * 1204) // 1M
enum HdfVNodeClientStatus {
VNODE_CLIENT_RUNNING,
@@ -99,7 +99,7 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
}
svcMgr = DevSvcManagerClntGetInstance();
if (svcMgr == NULL) {
if (svcMgr == NULL || svcMgr->devSvcMgrIf == NULL) {
return NULL;
}
deviceObject = svcMgr->devSvcMgrIf->GetObject(svcMgr->devSvcMgrIf, serviceName);
@@ -146,7 +146,7 @@ static struct HdfSBuf *HdfSbufCopyFromUser(uintptr_t data, size_t size)
return NULL;
}
if (CopyFromUser((void*)kData, (void*)data, size) != 0) {
HDF_LOGE("%s:copy from user fail", __func__);
HDF_LOGE("%s:failed to copy from user", __func__);
OsalMemFree(kData);
return NULL;
}
@@ -172,7 +172,7 @@ static int HdfSbufCopyToUser(const struct HdfSBuf *sbuf, void *dstUser, size_t d
}
if (CopyToUser(dstUser, HdfSbufGetData(sbuf), sbufSize) != 0) {
HDF_LOGE("%s: copy buff data fail", __func__);
HDF_LOGE("%s: failed to copy buff data", __func__);
return HDF_ERR_IO;
}
@@ -207,7 +207,7 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
return HDF_ERR_INVALID_PARAM;
}
if (CopyFromUser(&bwr, (void*)bwrUser, sizeof(bwr)) != 0) {
HDF_LOGE("Copy from user failed");
HDF_LOGE("copy from user failed");
return HDF_FAILURE;
}
if (bwr.writeSize > MAX_RW_SIZE || bwr.readSize > MAX_RW_SIZE) {
@@ -216,12 +216,12 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
data = HdfSbufCopyFromUser(bwr.writeBuffer, bwr.writeSize);
if (data == NULL) {
HDF_LOGE("Vnode adapter bind data is null");
HDF_LOGE("vnode adapter bind data is null");
return HDF_FAILURE;
}
reply = HdfSBufObtainDefaultSize();
if (reply == NULL) {
HDF_LOGE("%s:oom", __func__);
HDF_LOGE("%s: oom", __func__);
HdfSBufRecycle(data);
return HDF_FAILURE;
}
@@ -235,7 +235,7 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
}
bwr.readConsumed = HdfSbufGetDataSize(reply);
if (CopyToUser(bwrUser, &bwr, sizeof(struct HdfWriteReadBuf)) != 0) {
HDF_LOGE("%s: copy bwr fail", __func__);
HDF_LOGE("%s: fail to copy bwr", __func__);
ret = HDF_FAILURE;
}
@@ -286,7 +286,7 @@ static int HdfVNodeAdapterReadDevEvent(struct HdfVNodeAdapterClient *client, uns
}
if (CopyToUser(bwrUser, &bwr, sizeof(struct HdfWriteReadBuf)) != 0) {
HDF_LOGE("%s: copy bwr fail", __func__);
HDF_LOGE("%s: failed to copy bwr", __func__);
ret = HDF_ERR_IO;
}
if (ret == HDF_SUCCESS) {
@@ -461,7 +461,6 @@ static struct HdfVNodeAdapterClient *HdfNewVNodeAdapterClient(struct HdfVNodeAda
client->serv = &adapter->ioService;
client->status = VNODE_CLIENT_RUNNING;
client->adapter = adapter;
client->eventQueueSize = 0;
client->ioServiceClient.device = (struct HdfDeviceObject *)adapter->ioService.target;
client->ioServiceClient.priv = NULL;
client->wakeup = 0;
@@ -565,26 +564,26 @@ struct HdfIoService *HdfIoServiceAdapterPublish(const char *serviceName, uint32_
};
if ((serviceName == NULL) || (mode > MAX_MODE_SIZE)) {
HDF_LOGE("Input param is invalid, mode is %x", mode);
HDF_LOGE("input param is invalid, mode is %x", mode);
return NULL;
}
vnodeAdapter = (struct HdfVNodeAdapter *)OsalMemCalloc(sizeof(struct HdfVNodeAdapter));
if (vnodeAdapter == NULL) {
HDF_LOGE("Alloc remote service is null");
HDF_LOGE("alloc remote service is null");
return NULL;
}
nodePathLength = strlen(serviceName) + strlen(DEV_NODE_PATH) + 1;
vnodeAdapter->vNodePath = (char *)OsalMemCalloc(nodePathLength);
if (vnodeAdapter->vNodePath == NULL) {
HDF_LOGE("Alloc vnode path is null");
HDF_LOGE("alloc vnode path is null");
OsalMemFree(vnodeAdapter);
return NULL;
}
if (sprintf_s(vnodeAdapter->vNodePath, nodePathLength, "%s%s", DEV_NODE_PATH, serviceName) < 0) {
HDF_LOGE("Get node path failed");
HDF_LOGE("failed to get node path");
OsalMemFree(vnodeAdapter->vNodePath);
OsalMemFree(vnodeAdapter);
return NULL;
@@ -602,7 +601,7 @@ struct HdfIoService *HdfIoServiceAdapterPublish(const char *serviceName, uint32_
}
ret = OsalRegisterCdev(vnodeAdapter->cdev, vnodeAdapter->vNodePath, mode, vnodeAdapter);
if (ret != 0) {
HDF_LOGE("register dev node %s failed, ret is: %d", vnodeAdapter->vNodePath, ret);
HDF_LOGE("failed to register dev node %s, ret is: %d", vnodeAdapter->vNodePath, ret);
OsalMutexDestroy(&vnodeAdapter->mutex);
goto error;
}
@@ -6,8 +6,8 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVICE_SERVICE_START_H
#define DEVICE_SERVICE_START_H
#ifndef DEVMGR_SERVICE_START_H
#define DEVMGR_SERVICE_START_H
enum {
DEV_MGR_SLOW_LOAD = 0,
@@ -19,4 +19,4 @@ int DeviceManagerStartStep2(void);
void DeviceManagerSetQuickLoad(int isQuickLoad);
int DeviceManagerIsQuickLoad(void);
#endif /* DEVICE_SERVICE_START_H */
#endif /* DEVMGR_SERVICE_START_H */
+8 -9
View File
@@ -31,8 +31,7 @@ static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf
return;
}
reply->readPos = 0;
reply->writePos = 0;
HdfSbufFlush(reply);
HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
while (HdfSListIteratorHasNext(&itHost)) {
hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
@@ -78,21 +77,21 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
case DEVMGR_UNLOAD_SERVICE:
svcName = HdfSbufReadString(data);
if (svcName == NULL) {
HDF_LOGE("%s: get svc name is null", __func__);
HDF_LOGE("%s: svc name is null", __func__);
break;
}
ret = DevSvcManagerClntUnsubscribeService(svcName);
break;
case DEVMGR_GET_SERVICE:
if (!HdfSbufReadInt32(data, &deviceClass)) {
HDF_LOGE("%s: get deviceClass failed", __func__);
HDF_LOGE("%s: failed to get deviceClass", __func__);
break;
}
GetDeviceServiceNameByClass(deviceClass, reply);
ret = HDF_SUCCESS;
break;
default:
HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, code);
HDF_LOGE("%s: unsupported configuration type: %d", __func__, code);
break;
}
OsalMutexUnlock(&devMgrSvc->devMgrMutex);
@@ -104,17 +103,17 @@ void DeviceManagerSetQuickLoad(int loadFlag)
g_isQuickLoad = loadFlag;
}
int DeviceManagerIsQuickLoad()
int DeviceManagerIsQuickLoad(void)
{
return g_isQuickLoad;
}
int DeviceManagerStart()
int DeviceManagerStart(void)
{
struct IDevmgrService *instance = DevmgrServiceGetInstance();
if (instance == NULL || instance->StartService == NULL) {
HDF_LOGE("Device manager start failed, service instance is null!");
HDF_LOGE("device manager start failed, service instance is null");
return HDF_FAILURE;
}
struct HdfIoService *ioService = HdfIoServicePublish(DEV_MGR_NODE, DEV_MGR_NODE_PERM);
@@ -131,7 +130,7 @@ int DeviceManagerStart()
int DeviceManagerStartStep2()
{
if (DeviceManagerIsQuickLoad() == DEV_MGR_SLOW_LOAD) {
HDF_LOGW("%s device manager is not set quick load!", __func__);
HDF_LOGW("%s: device manager is not set to QuickLoad mode", __func__);
return HDF_SUCCESS;
}
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+26 -21
View File
@@ -32,6 +32,7 @@
static struct DeviceResourceNode *g_hcsTreeRoot = NULL;
void HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size);
static bool CreateHcsToTree(void)
{
uint32_t length;
@@ -49,7 +50,7 @@ static bool CreateHcsToTree(void)
const struct DeviceResourceNode *HcsGetRootNode(void)
{
if ((g_hcsTreeRoot == NULL) && !CreateHcsToTree()) {
HDF_LOGE("%s failed", __func__);
HDF_LOGE("%s: failed", __func__);
return NULL;
}
return g_hcsTreeRoot;
@@ -80,12 +81,12 @@ static bool GetHostInfo(const struct DeviceResourceNode *hostNode, struct HdfHos
uint16_t readNum = 0;
if ((HcsGetString(hostNode, ATTR_HOST_NAME, &hostInfo->hostName, NULL) != HDF_SUCCESS) ||
(strcmp(hostInfo->hostName, "") == 0)) {
HDF_LOGW("%s get host name failed", __func__);
HDF_LOGW("%s: get host name failed", __func__);
return false;
}
if ((HcsGetUint16(hostNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) ||
(readNum > MAX_PRIORITY_NUM)) {
HDF_LOGW("%s get host priority failed, priority is: %d", __func__, readNum);
HDF_LOGW("%s: get host priority failed, priority is: %u", __func__, readNum);
return false;
}
hostInfo->priority = readNum;
@@ -103,7 +104,7 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
if (hdfManagerNode == NULL) {
HDF_LOGE("%s get hdf manager node is null", __func__);
HDF_LOGE("%s: get hdf manager node is null", __func__);
return false;
}
@@ -112,19 +113,17 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
struct HdfHostInfo *hostInfo = HdfHostInfoNewInstance();
if (hostInfo == NULL) {
HdfSListFlush(hostList, HdfHostInfoDelete);
HDF_LOGE("%s new hostInfo is null", __func__);
HDF_LOGE("%s: new hostInfo is null", __func__);
return false;
}
if (!GetHostInfo(hostNode, hostInfo)) {
HdfHostInfoFreeInstance(hostInfo);
hostInfo = NULL;
hostNode = hostNode->sibling;
continue;
}
hostInfo->hostId = hostId;
if (!HdfSListAddOrder(hostList, &hostInfo->node, HdfHostListCompare)) {
HdfHostInfoFreeInstance(hostInfo);
hostInfo = NULL;
hostNode = hostNode->sibling;
continue;
}
@@ -149,7 +148,9 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
const struct DeviceResourceNode *hdfManagerNode = NULL;
const struct DeviceResourceNode *hostNode = NULL;
const char *hostName = NULL;
if (inHostName == NULL) {
return NULL;
}
hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
if (hdfManagerNode == NULL) {
return NULL;
@@ -171,17 +172,17 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
{
if (deviceNodeInfo->policy > SERVICE_POLICY_PRIVATE) {
HDF_LOGE("%s policy is invalid", __func__);
HDF_LOGE("%s: policy %u is invalid", __func__, deviceNodeInfo->policy);
return false;
}
if (deviceNodeInfo->priority > MAX_PRIORITY_NUM) {
HDF_LOGE("%s priority is invalid", __func__);
HDF_LOGE("%s: priority %u is invalid", __func__, deviceNodeInfo->priority);
return false;
}
if (deviceNodeInfo->preload > DEVICE_PRELOAD_DISABLE) {
HDF_LOGE("%s preload is invalid", __func__);
HDF_LOGE("%s: preload %u is invalid", __func__, deviceNodeInfo->preload);
return false;
}
@@ -193,43 +194,43 @@ static bool GetDeviceNodeInfo(const struct DeviceResourceNode *deviceNode, struc
uint16_t readNum = 0;
const char *readString = NULL;
if (HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &readNum, 0) != HDF_SUCCESS) {
HDF_LOGE("%s get policy failed", __func__);
HDF_LOGE("%s: failed to get policy", __func__);
return false;
}
deviceNodeInfo->policy = readNum;
if (HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) {
HDF_LOGE("%s get priority failed", __func__);
HDF_LOGE("%s: failed to get priority", __func__);
return false;
}
deviceNodeInfo->priority = readNum;
if (HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &readNum, 0) != HDF_SUCCESS) {
HDF_LOGE("%s get preload failed", __func__);
HDF_LOGE("%s: failed to get preload", __func__);
return false;
}
deviceNodeInfo->preload = readNum;
if (HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &readNum, 0) != HDF_SUCCESS) {
HDF_LOGE("%s get permission failed", __func__);
HDF_LOGE("%s: failed to get permission", __func__);
return false;
}
deviceNodeInfo->permission = readNum;
if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &readString, NULL) != HDF_SUCCESS) {
HDF_LOGE("%s get module name failed", __func__);
HDF_LOGE("%s: failed to get module name", __func__);
return false;
}
deviceNodeInfo->moduleName = readString;
if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &readString, NULL) != HDF_SUCCESS) {
HDF_LOGE("%s get service name failed", __func__);
HDF_LOGE("%s: failed to get service name", __func__);
return false;
}
deviceNodeInfo->svcName = readString;
if (HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &readString, NULL) != HDF_SUCCESS) {
HDF_LOGE("%s get service name failed", __func__);
HDF_LOGE("%s: failed to get matchattr name", __func__);
return false;
}
deviceNodeInfo->deviceMatchAttr = readString;
@@ -260,13 +261,13 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h
deviceNodeInfo->hostId = hostId;
if (!GetDeviceNodeInfo(deviceNode, deviceNodeInfo)) {
HdfDeviceInfoFreeInstance(deviceNodeInfo);
HDF_LOGE("%s get device failed", __func__);
HDF_LOGE("%s: failed to get device", __func__);
deviceNodeInfo = NULL;
deviceNode = deviceNode->sibling;
continue;
}
if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->node, HdfDeviceListCompare)) {
HDF_LOGE("%s add device %s failed", __func__, deviceNodeInfo->svcName);
HDF_LOGE("%s: failed to add device %s", __func__, deviceNodeInfo->svcName);
HdfDeviceInfoFreeInstance(deviceNodeInfo);
deviceNodeInfo = NULL;
deviceNode = deviceNode->sibling;
@@ -323,7 +324,11 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName)
if (svcName == NULL) {
break;
}
strcpy(svcName, serviceName);
if (strcpy_s(svcName, strlen(serviceName) + 1, serviceName) != EOK) {
HDF_LOGE("%s: failed to copy string", __func__);
OsalMemFree(svcName);
break;
}
deviceNodeInfo->svcName = svcName;
HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node);
hostClnt->devCount++;
+6 -6
View File
@@ -24,29 +24,29 @@ static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBu
struct HdfDeviceNode *devNode = NULL;
if (stub == NULL) {
HDF_LOGE("input ioService null");
HDF_LOGE("device ext dispatch: stub is null");
return HDF_FAILURE;
}
uint64_t ioClientPtr = 0;
if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) {
HDF_LOGE("input ioClient null");
HDF_LOGE("device ext dispatch: input ioClient is null");
return HDF_FAILURE;
}
HdfSbufFlush(reply);
devNode = CONTAINER_OF(stub, struct HdfDeviceNode, deviceObject);
deviceMethod = devNode->deviceObject.service;
if (deviceMethod == NULL) {
HDF_LOGE("Device service interface is null");
HDF_LOGE("device ext dispatch: device service interface is null");
return HDF_FAILURE;
}
deviceInfo = devNode->deviceInfo;
if (deviceInfo == NULL) {
HDF_LOGE("Device deviceInfo is null");
HDF_LOGE("device ext dispatch: device deviceInfo is null");
return HDF_FAILURE;
}
if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
if (deviceMethod->Dispatch == NULL) {
HDF_LOGE("Remote service dispatch is null");
HDF_LOGE("device ext dispatch: remote service dispatch method is null");
return HDF_FAILURE;
}
return deviceMethod->Dispatch((struct HdfDeviceIoClient *)((uintptr_t)ioClientPtr), code, data, reply);
@@ -64,7 +64,7 @@ static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *s
}
int ret = HdfDeviceNodePublishPublicService(inst, serviceName);
if (ret != HDF_SUCCESS) {
HDF_LOGE("Device publish service failed, ret is: %d", ret);
HDF_LOGE("failed to publish device service, ret is %d", ret);
return HDF_FAILURE;
}
+8 -8
View File
@@ -15,12 +15,12 @@ static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
int i;
*driverCount = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t));
if (*driverCount <= 0) {
HDF_LOGE("%s hdf get device counts failed!", __func__);
HDF_LOGE("%s: failed to hdf get device counts", __func__);
return NULL;
}
struct HdfDriverEntry *driverEntry = OsalMemCalloc(*driverCount * sizeof(struct HdfDriverEntry));
if (driverEntry == NULL) {
HDF_LOGE("%s hdf alloc driver entry mem failed!", __func__);
HDF_LOGE("%s: failed to alloc driver entry mem", __func__);
*driverCount = 0;
return NULL;
}
@@ -36,7 +36,7 @@ struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo
{
int i;
if ((deviceInfo == NULL) || (deviceInfo->moduleName == NULL) || (deviceInfo->svcName == NULL)) {
HDF_LOGE("%s hdf get device entry failed, input deviceInfo is NULL!", __func__);
HDF_LOGE("%s: failed to get device entry, input deviceInfo is NULL", __func__);
return NULL;
}
static struct HdfDriverEntry *driverEntry = NULL;
@@ -44,24 +44,24 @@ struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo
if (driverEntry == NULL) {
driverEntry = HdfDriverEntryConstruct(&driverCount);
if (driverEntry == NULL) {
HDF_LOGE("%s driver entry construct failed!", __func__);
HDF_LOGE("%s: failed to construct driver entry", __func__);
return NULL;
}
}
for (i = 0; i < driverCount; i++) {
if (driverEntry == NULL) {
HDF_LOGE("%s driver entry is null!", __func__);
HDF_LOGE("%s: driver entry is null", __func__);
return NULL;
}
if (driverEntry[i].moduleName == NULL) {
HDF_LOGE("%s driver entry module name is null!", __func__);
return NULL;
HDF_LOGE("%s: driver entry module name is null", __func__);
continue;
}
if (strcmp(deviceInfo->moduleName, driverEntry[i].moduleName) == 0) {
return &driverEntry[i];
}
}
HDF_LOGE("Hdf get %s device entry failed!", deviceInfo->svcName);
HDF_LOGE("failed to get device entry %s", deviceInfo->svcName);
return NULL;
}
+5 -2
View File
@@ -11,20 +11,23 @@
#include "devhost_service_if.h"
#include "hdf_service_observer.h"
#include "hdf_slist.h"
#include "hdf_dlist.h"
#include "osal_mutex.h"
#include "osal_sysevent.h"
struct DevHostService {
struct IDevHostService super;
uint16_t hostId;
const char *hostName;
struct HdfSList devices;
struct DListHead devices;
struct HdfServiceObserver observer;
struct HdfSysEventNotifyNode sysEventNotifyNode;
};
void DevHostServiceConstruct(struct DevHostService *service);
void DevHostServiceDestruct(struct DevHostService *service);
int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
struct IDevHostService *DevHostServiceNewInstance(uint16_t hostId, const char *hostName);
void DevHostServiceFreeInstance(struct IDevHostService *service);
struct HdfObject *DevHostServiceCreate(void);
+3 -2
View File
@@ -14,7 +14,7 @@
#include "hdf_device_desc.h"
#include "hdf_object.h"
#include "hdf_service_observer.h"
#include "hdf_slist.h"
#include "hdf_dlist.h"
#include "osal_mutex.h"
struct HdfDeviceNode;
@@ -22,11 +22,12 @@ struct HdfDeviceNode;
struct IHdfDevice {
struct HdfObject object;
int (*Attach)(struct IHdfDevice *, struct HdfDeviceNode *);
void (*Detach)(struct IHdfDevice *, struct HdfDeviceNode *);
};
struct HdfDevice {
struct IHdfDevice super;
struct HdfSListNode node;
struct DListHead node;
struct HdfSList services;
uint16_t deviceId;
uint16_t hostId;
+4 -1
View File
@@ -12,6 +12,7 @@
#include "hdf_device.h"
#include "hdf_device_info.h"
#include "hdf_device_desc.h"
#include "hdf_pm.h"
struct HdfDeviceNode;
struct DevHostService;
@@ -34,7 +35,9 @@ struct HdfDeviceNode {
};
int HdfDeviceNodeAddPowerStateListener(
struct HdfDeviceNode *devNode, struct IPowerEventListener *listener);
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener);
void HdfDeviceNodeRemovePowerStateListener(
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener);
void HdfDeviceNodeConstruct(struct HdfDeviceNode *service);
void HdfDeviceNodeDestruct(struct HdfDeviceNode *service);
struct HdfDeviceNode *HdfDeviceNodeNewInstance(void);
+2
View File
@@ -25,10 +25,12 @@ struct HdfDriverLoader {
};
struct HdfObject *HdfDriverLoaderCreate(void);
void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst);
void HdfDriverLoaderRelease(struct HdfObject *object);
struct IDriverLoader *HdfDriverLoaderGetInstance(void);
struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo);
struct HdfDeviceNode *HdfDriverLoaderLoadNode(
struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
#endif /* HDF_DRIVER_LOADER_H */
+5 -3
View File
@@ -11,17 +11,19 @@
#include "hdf_sref.h"
#include "power_state_token_if.h"
#include "hdf_pm.h"
struct PowerStateToken {
struct IPowerStateToken super;
struct IPowerEventListener *listener;
const struct IPowerEventListener *listener;
struct HdfDeviceObject *deviceObject;
struct HdfSRef wakeRef;
HdfPowerState state;
uint32_t mode;
};
struct PowerStateToken *PowerStateTokenNewInstance(
struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener);
struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken);
int PowerStateOnSysStateChange(struct PowerStateToken *stateToken, int32_t state);
#endif /* POWER_STATE_TOKEN_H */
+51 -39
View File
@@ -10,9 +10,7 @@
#include "devmgr_service_clnt.h"
#include "devsvc_manager_clnt.h"
#include "hdf_base.h"
#include "hdf_device_node_ext.h"
#include "hdf_driver_loader.h"
#include "hdf_io_service.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
#include "osal_mem.h"
@@ -21,17 +19,13 @@
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, uint16_t deviceId)
{
struct HdfSListIterator it;
struct HdfDevice *deviceNode = NULL;
if (inst == NULL) {
HDF_LOGE("Find driver failed, inst is null");
HDF_LOGE("failed to find driver, inst is null");
return NULL;
}
HdfSListIteratorInit(&it, &inst->devices);
while (HdfSListIteratorHasNext(&it)) {
deviceNode = (struct HdfDevice *)HDF_SLIST_CONTAINER_OF(
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDevice, node);
DLIST_FOR_EACH_ENTRY(deviceNode, &inst->devices, struct HdfDevice, node) {
if (deviceNode->deviceId == deviceId) {
return deviceNode;
}
@@ -43,7 +37,7 @@ static void DevHostServiceFreeDevice(struct DevHostService *inst, uint16_t devic
{
struct HdfDevice *deviceNode = DevHostServiceFindDevice(inst, deviceId);
if (deviceNode != NULL) {
HdfSListRemove(&inst->devices, &deviceNode->node);
DListRemove(&deviceNode->node);
HdfDeviceFreeInstance(deviceNode);
}
}
@@ -54,12 +48,12 @@ static struct HdfDevice *DevHostServiceGetDevice(struct DevHostService *inst, ui
if (device == NULL) {
device = HdfDeviceNewInstance();
if (device == NULL) {
HDF_LOGE("Dev host service create driver instance failed");
HDF_LOGE("Dev host service failed to create driver instance");
return NULL;
}
device->hostId = inst->hostId;
device->deviceId = deviceId;
HdfSListAdd(&inst->devices, &device->node);
DListInsertHead(&device->node, &inst->devices);
}
return device;
}
@@ -70,16 +64,16 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
struct HdfDevice *device = NULL;
struct HdfDeviceNode *devNode = NULL;
struct DevHostService *hostService = (struct DevHostService *)inst;
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->LoadNode == NULL)) {
HDF_LOGE("Add device failed, input param is null");
HDF_LOGE("failed to add device, input param is null");
return ret;
}
device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
if (device == NULL || device->super.Attach == NULL) {
ret = HDF_DEV_ERR_NO_MEMORY;
if ((device == NULL) || (device->super.Attach == NULL)) {
ret = HDF_DEV_ERR_NO_DEVICE;
goto error;
}
@@ -96,48 +90,58 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
return HDF_SUCCESS;
error:
if (!HdfSListIsEmpty(&hostService->devices)) {
DevHostServiceFreeDevice(hostService, deviceInfo->deviceId);
if (DListIsEmpty(&hostService->devices)) {
DevHostServiceFreeDevice(hostService, hostService->hostId);
}
return ret;
}
static int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
static struct HdfDeviceNode *DevHostServiceGetDeviceNode(struct HdfSList *deviceNodes,
const struct HdfDeviceInfo *deviceInfo)
{
struct HdfSListIterator it;
struct HdfDeviceNode *deviceNode = NULL;
HdfSListIteratorInit(&it, deviceNodes);
while (HdfSListIteratorHasNext(&it)) {
deviceNode = HDF_SLIST_CONTAINER_OF(
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDeviceNode, entry);
if (strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0 &&
strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) {
HdfSListRemove(deviceNodes, &deviceNode->entry);
return deviceNode;
}
}
return NULL;
}
int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
{
struct HdfDevice *device = NULL;
struct DevHostService *hostService = (struct DevHostService *)inst;
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->UnLoadNode == NULL)) {
HDF_LOGE("Add device failed, input param is null");
HDF_LOGE("failed to del device, input param is null");
return HDF_FAILURE;
}
device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
if (device == NULL) {
HDF_LOGW("Del device failed, device is not exist");
HDF_LOGW("failed to del device, device is not exist");
return HDF_SUCCESS;
}
driverLoader->UnLoadNode(driverLoader, deviceInfo);
struct HdfSListIterator it;
struct HdfDeviceNode *deviceNode = NULL;
HdfSListIteratorInit(&it, &device->services);
while (HdfSListIteratorHasNext(&it)) {
deviceNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDeviceNode, entry);
if ((strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) &&
(strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0)) {
struct DeviceNodeExt *deviceNodeExt = (struct DeviceNodeExt *)deviceNode;
HdfSListRemove(&device->services, &deviceNode->entry);
DeviceNodeExtRelease(&deviceNodeExt->super.super.object);
}
}
if (!HdfSListIsEmpty(&hostService->devices)) {
DevHostServiceFreeDevice(hostService, device->deviceId);
struct HdfDeviceNode *devNode = DevHostServiceGetDeviceNode(&device->services, deviceInfo);
if (device->super.Detach != NULL) {
device->super.Detach(&device->super, devNode);
} else {
HdfDeviceNodeFreeInstance(devNode);
}
DevSvcManagerClntRemoveService(deviceInfo->svcName);
if (HdfSListIsEmpty(&device->services)) {
DevHostServiceFreeDevice(hostService, device->deviceId);
}
return HDF_SUCCESS;
}
@@ -145,7 +149,7 @@ static int DevHostServiceStartService(struct IDevHostService *service)
{
struct DevHostService *hostService = (struct DevHostService*)service;
if (hostService == NULL) {
HDF_LOGE("Start device service failed, hostService is null");
HDF_LOGE("failed to start device service, hostService is null");
return HDF_FAILURE;
}
return DevmgrServiceClntAttachDeviceHost(hostService->hostId, service);
@@ -158,14 +162,22 @@ void DevHostServiceConstruct(struct DevHostService *service)
hostServiceIf->AddDevice = DevHostServiceAddDevice;
hostServiceIf->DelDevice = DevHostServiceDelDevice;
hostServiceIf->StartService = DevHostServiceStartService;
HdfSListInit(&service->devices);
DListHeadInit(&service->devices);
HdfServiceObserverConstruct(&service->observer);
}
}
void DevHostServiceDestruct(struct DevHostService *service)
{
HdfSListFlush(&service->devices, HdfDeviceDelete);
if (service == NULL) {
return;
}
struct HdfDevice *device = NULL;
struct HdfDevice *tmp = NULL;
DLIST_FOR_EACH_ENTRY_SAFE(device, tmp, &service->devices, struct HdfDevice, node) {
HdfDeviceFreeInstance(device);
}
HdfServiceObserverDestruct(&service->observer);
}
+4 -4
View File
@@ -19,13 +19,13 @@ int DevmgrServiceClntAttachDeviceHost(uint16_t hostId, struct IDevHostService *h
struct IDevmgrService *devMgrSvcIf = NULL;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
if ((inst == NULL) || (inst->devMgrSvcIf == NULL)) {
HDF_LOGE("Attach device host failed, get device manager service client is null");
HDF_LOGE("failed to attach device host, get device manager service client is null");
return HDF_FAILURE;
}
devMgrSvcIf = inst->devMgrSvcIf;
if (devMgrSvcIf->AttachDeviceHost == NULL) {
HDF_LOGE("Attach device host failed, attach device host function is null");
HDF_LOGE("failed to attach device host, attach device host function is null");
return HDF_FAILURE;
}
return devMgrSvcIf->AttachDeviceHost(devMgrSvcIf, hostId, hostService);
@@ -36,13 +36,13 @@ int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct
struct IDevmgrService *devMgrSvcIf = NULL;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
if ((inst == NULL) || (inst->devMgrSvcIf == NULL)) {
HDF_LOGE("Device manager service client attach device failed, inst is null");
HDF_LOGE("devmgr client failed to attach device, inst is null");
return HDF_FAILURE;
}
devMgrSvcIf = inst->devMgrSvcIf;
if (devMgrSvcIf->AttachDevice == NULL) {
HDF_LOGE("Device manager service client attach device failed, dmsOps->AttachDevice is nul");
HDF_LOGE("devmgr client failed to attach device, dmsOps->AttachDevice is nul");
return HDF_FAILURE;
}
return devMgrSvcIf->AttachDevice(devMgrSvcIf, deviceInfo, deviceToken);
+15 -19
View File
@@ -20,13 +20,13 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
if (devSvcMgrClnt == NULL) {
HDF_LOGE("Get device manager client is null");
HDF_LOGE("failed to add service, client is null");
return HDF_FAILURE;
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->AddService == NULL) {
HDF_LOGE("AddService function is not assigned");
HDF_LOGE("serviceManager AddService function is null");
return HDF_FAILURE;
}
return serviceManager->AddService(serviceManager, svcName, service);
@@ -36,13 +36,13 @@ const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
if (devSvcMgrClnt == NULL) {
HDF_LOGE("Get device manager client is null");
HDF_LOGE("failed to get service, client is null");
return NULL;
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->GetService == NULL) {
HDF_LOGE("GetService function is not assigned");
HDF_LOGE("serviceManager GetService function is null");
return NULL;
}
return serviceManager->GetService(serviceManager, svcName);
@@ -52,13 +52,13 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
if (devSvcMgrClnt == NULL) {
HDF_LOGE("Get device manager client is null");
HDF_LOGE("failed to get device object, client is null");
return NULL;
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->GetObject == NULL) {
HDF_LOGE("GetObject function is not assigned");
HDF_LOGE("failed to get device object, method not implement");
return NULL;
}
return serviceManager->GetObject(serviceManager, svcName);
@@ -82,10 +82,8 @@ struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *se
void HdfUnregisterDevice(const char *moduleName, const char *serviceName)
{
int ret;
ret = DevmgrServiceUnLoadDevice(serviceName);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s unload device %s failed!", __func__, serviceName);
if (DevmgrServiceUnLoadDevice(serviceName) != HDF_SUCCESS) {
HDF_LOGE("%s:failed to unload device %s !", __func__, serviceName);
}
HdfDeviceListDel(moduleName, serviceName);
}
@@ -94,13 +92,13 @@ int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCall
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
if (devSvcMgrClnt == NULL) {
HDF_LOGE("Get device manager client is null");
HDF_LOGE("failed to subscribe service, client is null");
return HDF_FAILURE;
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->SubscribeService == NULL) {
HDF_LOGE("SubscribeService function is not assigned");
HDF_LOGE("failed to subscribe service, method not implement");
return HDF_FAILURE;
}
return serviceManager->SubscribeService(serviceManager, svcName, callback);
@@ -110,13 +108,13 @@ int DevSvcManagerClntUnsubscribeService(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
if (devSvcMgrClnt == NULL) {
HDF_LOGE("Get device manager client is null");
HDF_LOGE("failed to unsubscribe service, client is null");
return HDF_FAILURE;
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->UnsubscribeService == NULL) {
HDF_LOGE("UnsubService function is not assigned");
HDF_LOGE("failed to unsubscribe service, method not implement");
return HDF_FAILURE;
}
return serviceManager->UnsubscribeService(serviceManager, svcName);
@@ -126,13 +124,13 @@ void DevSvcManagerClntRemoveService(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
if (devSvcMgrClnt == NULL) {
HDF_LOGE("Get device manager client is null");
HDF_LOGE("failed to remove service, devSvcMgrClnt is null");
return;
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->RemoveService == NULL) {
HDF_LOGE("Remove service function is not assigned");
HDF_LOGE("failed to remove service, method not implement");
return;
}
serviceManager->RemoveService(serviceManager, svcName);
@@ -157,9 +155,7 @@ struct DevSvcManagerClnt *DevSvcManagerClntGetInstance()
void DevSvcManagerClntFreeInstance(struct DevSvcManagerClnt *instance)
{
if (instance != NULL) {
if (instance->devSvcMgrIf != NULL) {
HdfObjectManagerFreeObject((struct HdfObject *)instance->devSvcMgrIf);
}
HdfObjectManagerFreeObject((struct HdfObject *)instance->devSvcMgrIf);
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev
struct HdfDevice *device = (struct HdfDevice *)devInst;
struct IDeviceNode *nodeIf = (struct IDeviceNode *)devNode;
if (device == NULL || nodeIf == NULL || nodeIf->LaunchNode == NULL) {
HDF_LOGE("Device attach failed, input params is wrong");
HDF_LOGE("failed to attach device, input params invalid");
return HDF_ERR_INVALID_PARAM;
}
HdfSListAdd(&device->services, &devNode->entry);
+24 -11
View File
@@ -26,12 +26,12 @@ static int HdfDeviceNodePublishLocalService(
{
uint32_t matchId;
if ((devNode == NULL) || (deviceInfo == NULL)) {
HDF_LOGE("Publish local service failed, device is null");
HDF_LOGE("failed to publish local service, device is null");
return HDF_FAILURE;
}
struct DevHostService *hostService = devNode->hostService;
if (hostService == NULL) {
HDF_LOGE("Publish local service failed, host service is null");
HDF_LOGE("failed to publish local service, host service is null");
return HDF_FAILURE;
}
matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
@@ -44,7 +44,8 @@ static int HdfDeviceNodePublishService(
{
(void)device;
int status = HDF_SUCCESS;
if (deviceInfo->policy == SERVICE_POLICY_NONE) {
if ((deviceInfo->policy == SERVICE_POLICY_NONE) ||
((deviceInfo->svcName != NULL) && (strlen(deviceInfo->svcName) == 0))) {
HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
return status;
}
@@ -66,7 +67,7 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
{
struct HdfDevice *device = (struct HdfDevice *)devInst;
if (device == NULL || devNode == NULL) {
HDF_LOGE("Launch service failed, device or service is null");
HDF_LOGE("failed to launch service, device or service is null");
return HDF_ERR_INVALID_PARAM;
}
@@ -75,12 +76,12 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
struct IHdfDeviceToken *deviceToken = NULL;
if (deviceInfo == NULL) {
HDF_LOGE("Launch service failed, deviceInfo is null");
HDF_LOGE("failed to launch service, deviceInfo is null");
return HDF_ERR_INVALID_PARAM;
}
if ((driverEntry == NULL) || (driverEntry->Init == NULL)) {
HDF_LOGE("deviceEntry or deviceEntry->Init is null");
HDF_LOGE("failed to launch service, deviceEntry invalid");
return HDF_ERR_INVALID_PARAM;
}
int ret = driverEntry->Init(&devNode->deviceObject);
@@ -109,21 +110,33 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
}
int HdfDeviceNodeAddPowerStateListener(
struct HdfDeviceNode *devNode, struct IPowerEventListener *listener)
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener)
{
if (devNode->powerToken != NULL) {
return HDF_FAILURE;
}
if (devNode->powerToken == NULL) {
devNode->powerToken = PowerStateTokenNewInstance(&devNode->deviceObject, listener);
}
devNode->powerToken = PowerStateTokenNewInstance(&devNode->deviceObject, listener);
return (devNode->powerToken != NULL) ? HDF_SUCCESS : HDF_FAILURE;
}
void HdfDeviceNodeRemovePowerStateListener(
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener)
{
(void)listener;
if (devNode == NULL || devNode->powerToken == NULL) {
return;
}
PowerStateTokenFreeInstance(devNode->powerToken);
devNode->powerToken = NULL;
}
int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode, const char *svcName)
{
if ((devNode == NULL) || (devNode->deviceObject.service == NULL)) {
HDF_LOGE("device method is null");
HDF_LOGE("failed to publish public service: devNode is NULL");
return HDF_FAILURE;
}
return DevSvcManagerClntAddService(svcName, &devNode->deviceObject);
+35 -12
View File
@@ -23,19 +23,19 @@ int32_t HdfDeviceSubscribeService(
struct DevHostService *hostService = NULL;
const struct HdfDeviceInfo *deviceInfo = NULL;
if (deviceObject == NULL || serviceName == NULL) {
HDF_LOGE("%s input param is invalid", __func__);
HDF_LOGE("failed to subscribe service, deviceObject/serviceName is null");
return HDF_FAILURE;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
hostService = devNode->hostService;
if (hostService == NULL) {
HDF_LOGE("Get host service is null");
HDF_LOGE("failed to subscribe service, hostService is null");
return HDF_FAILURE;
}
deviceInfo = devNode->deviceInfo;
if (deviceInfo == NULL) {
HDF_LOGE("Get device deviceInfo is null");
HDF_LOGE("failed to subscribe service, deviceInfo is null");
return HDF_FAILURE;
}
matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
@@ -45,34 +45,43 @@ int32_t HdfDeviceSubscribeService(
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
{
if (deviceObject == NULL) {
HDF_LOGE("%s input param is invalid", __func__);
HDF_LOGE("failed to get service name, deviceObject is invalid");
return NULL;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
if (deviceInfo == NULL) {
HDF_LOGE("Get device deviceInfo is null");
HDF_LOGE("failed to get service name, deviceInfo is null");
return NULL;
}
return deviceInfo->svcName;
}
void HdfDeviceRegisterPowerListener(struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
{
if (deviceObject == NULL) {
return HDF_ERR_INVALID_PARAM;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
return HdfDeviceNodeAddPowerStateListener(devNode, listener);
}
void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
{
if (deviceObject == NULL) {
HDF_LOGE("%s input param is invalid", __func__);
return;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
HdfDeviceNodeAddPowerStateListener(devNode, listener);
HdfDeviceNodeRemovePowerStateListener(devNode, listener);
}
void HdfDeviceAcquireWakeLock(struct HdfDeviceObject *deviceObject)
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject)
{
if (deviceObject == NULL) {
HDF_LOGE("%s input param is invalid", __func__);
HDF_LOGE("%s: input param is invalid", __func__);
return;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
@@ -83,10 +92,10 @@ void HdfDeviceAcquireWakeLock(struct HdfDeviceObject *deviceObject)
}
}
void HdfDeviceReleaseWakeLock(struct HdfDeviceObject *deviceObject)
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject)
{
if (deviceObject == NULL) {
HDF_LOGE("%s input param is invalid", __func__);
HDF_LOGE("%s: input param is invalid", __func__);
return;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
@@ -97,6 +106,20 @@ void HdfDeviceReleaseWakeLock(struct HdfDeviceObject *deviceObject)
}
}
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
{
if (deviceObject == NULL || mode > HDF_POWER_MODE_MAX) {
HDF_LOGE("%s: input param is invalid", __func__);
return;
}
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
struct PowerStateToken *token = devNode->powerToken;
if (token != NULL) {
token->mode = mode;
}
}
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
{
if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) ||
+19 -14
View File
@@ -23,27 +23,28 @@ struct HdfDeviceNode *HdfDriverLoaderLoadNode(
struct HdfDriverEntry *driverEntry = NULL;
struct HdfDeviceNode *devNode = NULL;
if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
HDF_LOGE("loader or loader->GetDriverEntry is null");
HDF_LOGE("failed to load node, loader is invalid");
return NULL;
}
driverEntry = loader->GetDriverEntry(deviceInfo);
if (driverEntry == NULL) {
HDF_LOGE("Load service failed, deviceEntry is null");
HDF_LOGE("failed to load node, deviceEntry is null");
return NULL;
}
devNode = HdfDeviceNodeNewInstance();
if (devNode == NULL) {
HDF_LOGE("Load service failed, device node is null");
HDF_LOGE("failed to load node, device node is null");
return NULL;
}
devNode->driverEntry = driverEntry;
devNode->deviceInfo = deviceInfo;
devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr);
if (devNode->deviceObject.property == NULL) {
HDF_LOGW("Get property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
HDF_LOGW("failed to load node, property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
}
if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) || (deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
@@ -61,34 +62,38 @@ struct HdfDeviceNode *HdfDriverLoaderLoadNode(
return devNode;
}
static void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
{
struct HdfDriverEntry *driverEntry = NULL;
struct HdfDeviceObject *deviceObject = NULL;
if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
HDF_LOGE("loader or loader->GetDriverEntry is null");
HDF_LOGE("failed to unload service, loader invalid");
return;
}
driverEntry = loader->GetDriverEntry(deviceInfo);
if (driverEntry == NULL) {
HDF_LOGE("Load service failed, driverEntry is null");
HDF_LOGE("failed to unload service, driverEntry is null");
return;
}
if (driverEntry->Release == NULL) {
HDF_LOGI("Device Release func is null");
HDF_LOGI("device release func is null");
return;
}
deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName);
driverEntry->Release(deviceObject);
if (deviceObject != NULL) {
driverEntry->Release(deviceObject);
}
}
static void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst)
void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst)
{
struct IDriverLoader *driverLoaderIf = (struct IDriverLoader *)inst;
driverLoaderIf->LoadNode = HdfDriverLoaderLoadNode;
driverLoaderIf->UnLoadNode = HdfDriverLoaderUnLoadNode;
driverLoaderIf->GetDriverEntry = HdfDriverLoaderGetDriverEntry;
if (inst != NULL) {
struct IDriverLoader *driverLoaderIf = (struct IDriverLoader *)inst;
driverLoaderIf->LoadNode = HdfDriverLoaderLoadNode;
driverLoaderIf->UnLoadNode = HdfDriverLoaderUnLoadNode;
driverLoaderIf->GetDriverEntry = HdfDriverLoaderGetDriverEntry;
}
}
struct HdfObject *HdfDriverLoaderCreate()
+1 -3
View File
@@ -16,9 +16,7 @@
uint32_t HdfMakeHardwareId(uint16_t hostId, uint16_t deviceId)
{
uint32_t hardwareId = hostId;
hardwareId = (hardwareId << HALF_INT_LEN) | deviceId;
return hardwareId;
return ((uint32_t)hostId << HALF_INT_LEN) | deviceId;
}
struct HdfServiceObserverRecord *HdfServiceObserverRecordObtain(uint32_t serviceKey)
+7 -4
View File
@@ -32,7 +32,6 @@ void HdfServiceObserverDestruct(struct HdfServiceObserver *observer)
if (observer != NULL) {
HdfSListFlush(&observer->services, HdfServiceObserverRecordDelete);
OsalMutexDestroy(&observer->observerMutex);
observer->observerMutex.realMutex = NULL;
}
}
@@ -51,20 +50,22 @@ int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
if (serviceRecord == NULL) {
serviceRecord = HdfServiceObserverRecordObtain(serviceKey);
if (serviceRecord == NULL) {
HDF_LOGE("SubscribeService failed, serviceRecord is null");
HDF_LOGE("failed to subscribe service, serviceRecord is null");
return HDF_FAILURE;
}
subscriber = HdfServiceSubscriberObtain(callback, matchId);
if (subscriber == NULL) {
HDF_LOGE("SubscribeService failed, subscriber is null");
HDF_LOGE("failed to subscribe service, subscriber is null");
HdfServiceObserverRecordRecycle(serviceRecord);
return HDF_FAILURE;
}
OsalMutexLock(&observer->observerMutex);
HdfSListAdd(&observer->services, &serviceRecord->entry);
OsalMutexUnlock(&observer->observerMutex);
} else {
subscriber = HdfServiceSubscriberObtain(callback, matchId);
if (subscriber == NULL) {
HDF_LOGE("SubscribeService failed, hdf search list is null, subscriber is null");
HDF_LOGE("failed to subscribe service, subscriber obtain null");
return HDF_FAILURE;
}
}
@@ -101,7 +102,9 @@ int HdfServiceObserverPublishService(struct HdfServiceObserver *observer,
serviceRecord->publisher = service;
serviceRecord->matchId = matchId;
serviceRecord->policy = policy;
OsalMutexLock(&observer->observerMutex);
HdfSListAdd(&observer->services, &serviceRecord->entry);
OsalMutexUnlock(&observer->observerMutex);
} else {
serviceRecord->publisher = service;
HdfServiceObserverRecordNotifySubscribers(serviceRecord, matchId, policy);
+1 -1
View File
@@ -6,8 +6,8 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "osal_mem.h"
#include "hdf_service_subscriber.h"
#include "osal_mem.h"
struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, uint32_t matchId)
{
+124 -65
View File
@@ -11,12 +11,110 @@
#include "hdf_device_desc.h"
#include "hdf_slist.h"
#include "osal_mem.h"
#include "osal_sysevent.h"
static void PowerStateTokenAcqureWakeLock(struct IPowerStateToken *token)
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
{
if (sref == NULL) {
return;
}
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
if (stateToken->state == POWER_STATE_ACTIVE) {
return;
}
struct IDevmgrService *devMgrSvcIf = NULL;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
if (inst == NULL) {
return;
}
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
if (devMgrSvcIf != NULL && devMgrSvcIf->AcquireWakeLock != NULL) {
devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
}
if (stateToken->state == POWER_STATE_INACTIVE || stateToken->state == POWER_STATE_IDLE) {
const struct IPowerEventListener *listener = stateToken->listener;
if ((listener != NULL) && (listener->Resume != NULL)) {
listener->Resume(stateToken->deviceObject);
}
}
stateToken->state = POWER_STATE_ACTIVE;
}
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
{
if (sref == NULL) {
return;
}
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
if (stateToken->state != POWER_STATE_ACTIVE && stateToken->state != POWER_STATE_IDLE) {
return;
}
struct IDevmgrService *devMgrSvcIf = NULL;
const struct IPowerEventListener *listener = stateToken->listener;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
if (inst == NULL) {
return;
}
if (stateToken->state == POWER_STATE_ACTIVE) {
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
if ((devMgrSvcIf != NULL) && (devMgrSvcIf->AcquireWakeLock != NULL)) {
devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
}
}
if ((listener != NULL) && (listener->Suspend != NULL)) {
listener->Suspend(stateToken->deviceObject);
}
stateToken->state = POWER_STATE_INACTIVE;
}
int PowerStateOnSysStateChange(struct PowerStateToken *stateToken, int32_t state)
{
if (stateToken == NULL || stateToken->listener == NULL || stateToken->mode != HDF_POWER_SYS_CTRL) {
return HDF_SUCCESS;
}
switch (state) {
case KEVENT_POWER_SUSPEND:
if (stateToken->listener->Suspend != NULL) {
return stateToken->listener->Suspend(stateToken->deviceObject);
}
break;
case KEVENT_POWER_RESUME:
if (stateToken->listener->Resume != NULL) {
return stateToken->listener->Resume(stateToken->deviceObject);
}
break;
case KEVENT_POWER_DISPLAY_OFF:
if (stateToken->listener->DozeSuspend != NULL) {
return stateToken->listener->DozeSuspend(stateToken->deviceObject);
}
break;
case KEVENT_POWER_DISPLAY_ON:
if (stateToken->listener->DozeResume != NULL) {
return stateToken->listener->DozeResume(stateToken->deviceObject);
}
break;
default:
break;
}
return HDF_SUCCESS;
}
static void PowerStateTokenAcquireWakeLock(struct IPowerStateToken *token)
{
struct HdfSRef *sref = NULL;
struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
if (stateToken == NULL) {
if (stateToken == NULL || stateToken->mode != HDF_POWER_DYNAMIC_CTRL) {
return;
}
sref = (struct HdfSRef *)&stateToken->wakeRef;
@@ -29,79 +127,32 @@ static void PowerStateTokenReleaseWakeLock(struct IPowerStateToken *token)
{
struct HdfSRef *sref = NULL;
struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
if (stateToken == NULL) {
if (stateToken == NULL || stateToken->mode != HDF_POWER_DYNAMIC_CTRL) {
return;
}
sref = (struct HdfSRef *)&stateToken->wakeRef;
if ((sref != NULL) && (sref->Release != NULL)) {
if ((sref == NULL) || (sref->Release == NULL)) {
return;
}
/* Not allowed to decrease the ref count to negative */
if (HdfSRefCount(sref) == 0) {
PowerStateTokenOnLastRelease(sref);
} else {
sref->Release(sref);
}
}
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
{
if (sref == NULL) {
return;
}
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
if (stateToken->state != POWER_STATE_ACTIVE) {
struct IDevmgrService *devMgrSvcIf = NULL;
struct IPowerEventListener* listener = stateToken->listener;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
if (inst == NULL) {
return;
}
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
if (devMgrSvcIf == NULL || devMgrSvcIf->AcquireWakeLock == NULL) {
return;
}
devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
if (stateToken->state == POWER_STATE_INACTIVE) {
if ((listener != NULL) && (listener->Resume != NULL)) {
listener->Resume(stateToken->deviceObject);
}
}
stateToken->state = POWER_STATE_ACTIVE;
}
}
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
{
if (sref == NULL) {
return;
}
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
if (stateToken->state == POWER_STATE_ACTIVE) {
struct IDevmgrService *devMgrSvcIf = NULL;
struct IPowerEventListener *listener = stateToken->listener;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
if (inst == NULL) {
return;
}
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
if ((devMgrSvcIf == NULL) || (devMgrSvcIf->AcquireWakeLock == NULL)) {
return;
}
devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
if ((listener != NULL) && (listener->Suspend != NULL)) {
listener->Suspend(stateToken->deviceObject);
}
stateToken->state = POWER_STATE_INACTIVE;
}
}
static void PowerStateTokenConstruct(
struct PowerStateToken *powerStateToken, struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
static int32_t PowerStateTokenConstruct(struct PowerStateToken *powerStateToken,
struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
{
struct IPowerStateToken *tokenIf = &powerStateToken->super;
struct IHdfSRefListener *srefListener = (struct IHdfSRefListener *)OsalMemCalloc(sizeof(struct IHdfSRefListener));
if (srefListener == NULL) {
return;
return HDF_ERR_MALLOC_FAIL;
}
tokenIf->AcquireWakeLock = PowerStateTokenAcqureWakeLock;
tokenIf->AcquireWakeLock = PowerStateTokenAcquireWakeLock;
tokenIf->ReleaseWakeLock = PowerStateTokenReleaseWakeLock;
srefListener->OnFirstAcquire = PowerStateTokenOnFirstAcquire;
@@ -111,16 +162,24 @@ static void PowerStateTokenConstruct(
powerStateToken->listener = listener;
powerStateToken->deviceObject = deviceObject;
HdfSRefConstruct(&powerStateToken->wakeRef, srefListener);
return HDF_SUCCESS;
}
struct PowerStateToken *PowerStateTokenNewInstance(
struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
{
struct PowerStateToken *stateToken =
(struct PowerStateToken *)OsalMemCalloc(sizeof(struct PowerStateToken));
if (stateToken != NULL) {
PowerStateTokenConstruct(stateToken, deviceObject, listener);
if (stateToken == NULL) {
return NULL;
}
if (PowerStateTokenConstruct(stateToken, deviceObject, listener) != HDF_SUCCESS) {
OsalMemFree(stateToken);
return NULL;
}
return stateToken;
}
+3 -1
View File
@@ -11,11 +11,13 @@
#include "devhost_service_if.h"
#include "hdf_slist.h"
#include "hdf_map.h"
struct DevHostServiceClnt {
struct HdfSListNode node;
struct HdfSList devices;
struct HdfSList *deviceInfos;
Map *deviceHashMap;
struct IDevHostService *hostService;
uint16_t devCount;
uint16_t hostId;
@@ -25,7 +27,7 @@ struct DevHostServiceClnt {
int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt);
struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName);
void DevHostServiceClntFreeInstance(struct DevHostServiceClnt* hostClnt);
void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt);
void DevHostServiceClntDelete(struct HdfSListNode *listEntry);
#endif /* DEVHOST_SERVICE_CLNT_H */
+3
View File
@@ -29,4 +29,7 @@ int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName,
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *manager, const char *svcName);
void DevSvcManagerRemoveService(struct IDevSvcManager *manager, const char *svcName);
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
int DevSvcManagerClntUnsubscribeService(const char *svcName);
#endif /* DEVICE_SERVICE_MANAGER_H */
@@ -16,7 +16,7 @@
struct PowerStateTokenClnt {
struct HdfSListNode entry;
HdfPowerState powerState;
struct IPowerStateToken* tokenIf;
struct IPowerStateToken *tokenIf;
};
struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf);
+9 -2
View File
@@ -23,7 +23,7 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
struct HdfDeviceInfo *deviceInfo = NULL;
struct IDevHostService *devHostSvcIf = NULL;
if (hostClnt == NULL) {
HDF_LOGE("Install driver failed, hostClnt is null");
HDF_LOGE("failed to install driver, hostClnt is null");
return HDF_FAILURE;
}
@@ -44,7 +44,7 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
}
ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
if (ret != HDF_SUCCESS) {
HDF_LOGE("Install %s driver failed, ret = %d", deviceInfo->svcName, ret);
HDF_LOGE("failed to install driver %s, ret = %d", deviceInfo->svcName, ret);
}
}
return HDF_SUCCESS;
@@ -53,6 +53,12 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
static void DevHostServiceClntConstruct(struct DevHostServiceClnt *hostClnt)
{
HdfSListInit(&hostClnt->devices);
hostClnt->deviceHashMap = (Map *)OsalMemCalloc(sizeof(Map));
if (hostClnt->deviceHashMap == NULL) {
HDF_LOGE("%s:failed to malloc deviceHashMap", __func__);
return;
}
MapInit(hostClnt->deviceHashMap);
}
struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName)
@@ -73,6 +79,7 @@ void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt)
if (hostClnt != NULL) {
HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
HdfSListFlush(hostClnt->deviceInfos, HdfDeviceInfoDelete);
OsalMemFree(hostClnt->deviceHashMap);
OsalMemFree(hostClnt);
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ struct DeviceTokenClnt *DeviceTokenClntNewInstance(struct IHdfDeviceToken *token
{
struct DeviceTokenClnt *tokenClnt = NULL;
if (tokenIf == NULL) {
HDF_LOGE("New token client failed, tokenIf is null");
HDF_LOGE("failed to create token client, tokenIf is null");
return NULL;
}
tokenClnt = (struct DeviceTokenClnt *)OsalMemCalloc(sizeof(struct DeviceTokenClnt));
+44 -20
View File
@@ -17,12 +17,15 @@
#include "hdf_object_manager.h"
#include "power_state_manager.h"
#define HDF_LOG_TAG devmgr_service
static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, struct HdfDeviceInfo *deviceInfo, bool isLoad)
{
struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
if (devHostSvcIf == NULL) {
return HDF_FAILURE;
}
if (isLoad && (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
int ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
if (ret == HDF_SUCCESS) {
@@ -83,7 +86,7 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
if (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
ret = DevmgrServiceActiveDevice(hostClnt, deviceInfo, true);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s load driver %s failed!", __func__, deviceInfo->moduleName);
HDF_LOGE("%s:failed to load driver %s", __func__, deviceInfo->moduleName);
}
}
}
@@ -91,7 +94,6 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
return HDF_SUCCESS;
}
int DevmgrServiceLoadDevice(const char *svcName)
{
return DevmgrServiceFindAndActiveDevice(svcName, true);
@@ -108,7 +110,7 @@ static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrServ
struct DevHostServiceClnt *hostClnt = NULL;
struct DevmgrService *dmService = (struct DevmgrService *)inst;
if (dmService == NULL) {
HDF_LOGE("Find device host failed, dmService is null");
HDF_LOGE("failed to find device host, dmService is null");
return NULL;
}
HdfSListIteratorInit(&it, &dmService->hosts);
@@ -118,29 +120,49 @@ static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrServ
return hostClnt;
}
}
HDF_LOGE("Find host failed, host id is %u", hostId);
HDF_LOGE("failed to find host, host id is %u", hostId);
return NULL;
}
static void DevmgrServiceUpdateStatus(struct DevHostServiceClnt *hostClnt, uint16_t deviceId, uint16_t status)
{
struct HdfSListIterator it;
struct HdfDeviceInfo *deviceInfo = NULL;
HdfSListIteratorInit(&it, hostClnt->deviceInfos);
while (HdfSListIteratorHasNext(&it)) {
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
if (deviceInfo->deviceId == deviceId) {
deviceInfo->status = status;
HDF_LOGD("%s host:%s %u device:%s %u status:%u", __func__, hostClnt->hostName,
hostClnt->hostId, deviceInfo->svcName, deviceId, deviceInfo->status);
return;
}
}
HDF_LOGE("%s: not find device %u in host %u", __func__, hostClnt->hostId, deviceId);
return;
}
static int DevmgrServiceAttachDevice(
struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token)
{
if (deviceInfo == NULL) {
HDF_LOGE("deviceInfo is null");
HDF_LOGE("failed to attach device, deviceInfo is null");
return HDF_FAILURE;
}
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, deviceInfo->hostId);
if (hostClnt == NULL) {
HDF_LOGE("hostClnt is null");
HDF_LOGE("failed to attach device, hostClnt is null");
return HDF_FAILURE;
}
struct DeviceTokenClnt *tokenClnt = DeviceTokenClntNewInstance(token);
if (tokenClnt == NULL) {
HDF_LOGE("tokenClnt is null");
HDF_LOGE("failed to attach device, tokenClnt is null");
return HDF_FAILURE;
}
tokenClnt->deviceInfo = deviceInfo;
DevmgrServiceUpdateStatus(hostClnt, deviceInfo->deviceId, HDF_SERVICE_USABLE);
HdfSListAdd(&hostClnt->devices, &tokenClnt->node);
return HDF_SUCCESS;
}
@@ -150,20 +172,21 @@ static int DevmgrServiceAttachDeviceHost(
{
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, hostId);
if (hostClnt == NULL) {
HDF_LOGE("Attach device host failed, hostClnt is null");
HDF_LOGE("failed to attach device host, hostClnt is null");
return HDF_FAILURE;
}
if (hostService == NULL) {
HDF_LOGE("Attach device host failed, hostService is null");
HDF_LOGE("failed to attach device host, hostService is null");
return HDF_FAILURE;
}
hostClnt->hostService = hostService;
hostClnt->deviceInfos = HdfAttributeManagerGetDeviceList(hostClnt->hostId, hostClnt->hostName);
if (hostClnt->deviceInfos == NULL) {
HDF_LOGE("Get device list failed");
return HDF_FAILURE;
HDF_LOGW("failed to get device list ");
return HDF_SUCCESS;
}
hostClnt->devCount = HdfSListCount(hostClnt->deviceInfos);
hostClnt->hostService = hostService;
return DevHostServiceClntInstallDriver(hostClnt);
}
@@ -181,7 +204,7 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
}
HdfSListInit(&hostList);
if (!HdfAttributeManagerGetHostList(&hostList)) {
HDF_LOGW("%s get host list is null", __func__);
HDF_LOGW("%s: host list is null", __func__);
return HDF_SUCCESS;
}
HdfSListIteratorInit(&it, &hostList);
@@ -189,13 +212,13 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
hostAttr = (struct HdfHostInfo *)HdfSListIteratorNext(&it);
hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
if (hostClnt == NULL) {
HDF_LOGW("Create new device host client failed");
HDF_LOGW("failed to create new device host client");
continue;
}
HdfSListAdd(&inst->hosts, &hostClnt->node);
hostClnt->hostPid = installer->StartDeviceHost(hostAttr->hostId, hostAttr->hostName);
if (hostClnt->hostPid == HDF_FAILURE) {
HDF_LOGW("Start device host failed, host id is %u", hostAttr->hostId);
HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId);
HdfSListRemove(&inst->hosts, &hostClnt->node);
DevHostServiceClntFreeInstance(hostClnt);
}
@@ -208,7 +231,7 @@ int DevmgrServiceStartService(struct IDevmgrService *inst)
{
struct DevmgrService *dmService = (struct DevmgrService *)inst;
if (dmService == NULL) {
HDF_LOGE("Start device manager service failed, dmService is null");
HDF_LOGE("failed to start device manager service, dmService is null");
return HDF_FAILURE;
}
return DevmgrServiceStartDeviceHosts(dmService);
@@ -217,7 +240,7 @@ int DevmgrServiceStartService(struct IDevmgrService *inst)
bool DevmgrServiceConstruct(struct DevmgrService *inst)
{
if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
HDF_LOGE("%s mutex init failed", __func__);
HDF_LOGE("%s:failed to mutex init ", __func__);
return false;
}
struct IDevmgrService *devMgrSvcIf = (struct IDevmgrService *)inst;
@@ -228,11 +251,12 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst)
devMgrSvcIf->AcquireWakeLock = DevmgrServiceAcquireWakeLock;
devMgrSvcIf->ReleaseWakeLock = DevmgrServiceReleaseWakeLock;
HdfSListInit(&inst->hosts);
return true;
} else {
return false;
}
return true;
}
struct HdfObject *DevmgrServiceCreate()
{
static bool isDevMgrServiceInit = false;
+6 -6
View File
@@ -16,14 +16,14 @@
#define HDF_LOG_TAG devsvc_manager
struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey)
static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey)
{
struct HdfSListIterator it;
struct DevSvcRecord *record = NULL;
struct DevSvcRecord *searchResult = NULL;
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
if (devSvcManager == NULL) {
HDF_LOGE("Search service failed, devSvcManager is null");
HDF_LOGE("failed to search service, devSvcManager is null");
return NULL;
}
@@ -44,13 +44,13 @@ int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, st
{
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
if ((devSvcManager == NULL) || (service == NULL) || (svcName == NULL)) {
HDF_LOGE("Add service failed, input param is null");
HDF_LOGE("failed to add service, input param is null");
return HDF_FAILURE;
}
struct DevSvcRecord *record = DevSvcRecordNewInstance();
if (record == NULL) {
HDF_LOGE("Add service failed, record is null");
HDF_LOGE("failed to add service , record is null");
return HDF_FAILURE;
}
@@ -94,6 +94,7 @@ void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName
HdfSListRemove(&devSvcManager->services, &serviceRecord->entry);
OsalMutexUnlock(&devSvcManager->mutex);
}
DevSvcRecordFreeInstance(serviceRecord);
}
struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, const char *svcName)
@@ -134,7 +135,7 @@ bool DevSvcManagerConstruct(struct DevSvcManager *inst)
devSvcMgrIf->GetObject = DevSvcManagerGetObject;
HdfSListInit(&inst->services);
if (OsalMutexInit(&inst->mutex) != HDF_SUCCESS) {
HDF_LOGE("Device service manager create mutex failed!");
HDF_LOGE("failed to create device service manager mutex");
return false;
}
return true;
@@ -171,4 +172,3 @@ struct IDevSvcManager *DevSvcManagerGetInstance()
}
return instance;
}
+1 -1
View File
@@ -23,7 +23,7 @@ static int DriverInstallerStartDeviceHost(uint32_t devHostId, const char *devHos
}
int ret = hostServiceIf->StartService(hostServiceIf);
if (ret != HDF_SUCCESS) {
HDF_LOGE("Start host service failed, ret is: %d", ret);
HDF_LOGE("failed to start host service, ret: %d", ret);
DevHostServiceFreeInstance(hostServiceIf);
}
return ret;
-1
View File
@@ -62,7 +62,6 @@ static void PowerStateManagerReleaseWakeLock(
static void PowerStateManagerConstruct(struct PowerStateManager *inst)
{
// not support system acquire and release
static struct IHdfSRefListener wakeLockRefListener = {
.OnFirstAcquire = NULL,
.OnLastRelease = NULL,
@@ -72,12 +72,12 @@ int IoServiceTest::OnDevEventReceived(struct HdfDevEventlistener *listener, stru
{
OsalTimespec time;
OsalGetTime(&time);
HDF_LOGE("%s received event[%d] from %s at %llu.%llu", (char *)listener->priv, eventCount++, (char *)service->priv,
HDF_LOGE("%s: received event[%d] from %s at %llu.%llu", (char *)listener->priv, eventCount++, (char *)service->priv,
time.sec, time.usec);
const char *string = HdfSbufReadString(data);
if (string == nullptr) {
HDF_LOGE("fail to read string in event data");
HDF_LOGE("failed to read string in event data");
return 0;
}
struct Eventlistener *l = CONTAINER_OF(listener, struct Eventlistener, listener);
@@ -140,7 +140,7 @@ static int SendEvent(struct HdfIoService *serv, const char *eventData)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level0)
{
struct HdfIoService *testServ = HdfIoServiceBind(testSvcName);
ASSERT_NE(testServ, nullptr);
@@ -149,11 +149,11 @@ HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level1)
/* *
* @tc.name: HdfIoService002
* @tc.desc: service group linten test
* @tc.desc: service group listen test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level0)
{
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
ASSERT_NE(serv, nullptr);
@@ -203,7 +203,7 @@ HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level0)
{
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
ASSERT_NE(serv, nullptr);
@@ -258,7 +258,7 @@ HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level0)
{
struct HdfIoService *serv1 = HdfIoServiceBind(testSvcName);
ASSERT_NE(serv1, nullptr);
@@ -283,7 +283,7 @@ HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level0)
{
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
ASSERT_NE(serv, nullptr);
@@ -467,7 +467,7 @@ HWTEST_F(IoServiceTest, HdfIoService008, TestSize.Level0)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level0)
{
struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
ASSERT_NE(group, nullptr);
@@ -504,7 +504,7 @@ HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level0)
{
struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
ASSERT_NE(group, nullptr);
@@ -544,7 +544,7 @@ HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level0)
{
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
ASSERT_NE(serv, nullptr);
@@ -573,7 +573,7 @@ HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level1)
HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level0)
{
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
ASSERT_NE(serv, nullptr);
@@ -84,19 +84,19 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
int32_t ret = HDF_FAILURE;
struct HdfSBuf *data = NULL;
struct HdfIoService *ioService = HdfIoServiceBind(SAMPLE_SERVICE);
ASSERT_TRUE(ioService != NULL);
EXPECT_TRUE(ioService != NULL);
data = HdfSBufObtainDefaultSize();
ASSERT_TRUE(data != NULL);
EXPECT_TRUE(data != NULL);
EXPECT_TRUE(HdfSbufWriteString(data, "sample_driver"));
EXPECT_TRUE(HdfSbufWriteString(data, "sample_service1"));
int64_t timeBefore = OsalGetSysTimeMs();
uint64_t timeBefore = OsalGetSysTimeMs();
ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_REGISTER_DEVICE, data, NULL);
EXPECT_TRUE(ret == HDF_SUCCESS);
int64_t timeAfter = OsalGetSysTimeMs();
uint64_t timeAfter = OsalGetSysTimeMs();
EXPECT_TRUE((timeAfter - timeBefore) < 100);
struct HdfIoService *ioService1 = HdfIoServiceBind("sample_service1");
ASSERT_TRUE(ioService1 != NULL);
EXPECT_TRUE(ioService1 != NULL);
HdfIoServiceRecycle(ioService1);
ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
@@ -21,7 +21,7 @@ static const int DEFAULT_LOOP_COUNT = 500;
static const int DEFAULT_BIG_LOOP_COUNT = 1000;
static const int DATA_MOD = 26;
class SBufTest : public ::testing::Test {
class HdfSBufTest : public ::testing::Test {
protected:
void SetUp() override {}
@@ -243,7 +243,7 @@ protected:
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestObtain001, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestObtain001, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtain(DEFAULT_SBUF_SIZE);
ASSERT_NE(sBuf, nullptr);
@@ -256,7 +256,7 @@ HWTEST_F(SBufTest, SbufTestObtain001, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestWriteUint64002, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestWriteUint64002, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -271,7 +271,7 @@ HWTEST_F(SBufTest, SbufTestWriteUint64002, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestWriteUint64Loop003, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestWriteUint64Loop003, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -288,7 +288,7 @@ HWTEST_F(SBufTest, SbufTestWriteUint64Loop003, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -297,7 +297,7 @@ HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
auto ret = HdfSbufWriteInt64(sBuf, INT64_MAX);
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
uint64_t val = 0;
for (int j = 0; j < loop; ++j) {
@@ -318,7 +318,7 @@ HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestInt8005, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -331,7 +331,7 @@ HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
int8_t val = 0;
@@ -351,7 +351,7 @@ HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestInt16006, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -364,7 +364,7 @@ HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
int16_t val = 0;
@@ -384,7 +384,7 @@ HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestInt32007, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -397,7 +397,7 @@ HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
int32_t val = 0;
@@ -417,7 +417,7 @@ HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestInt64008, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -430,7 +430,7 @@ HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint64_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
int64_t val = 0;
@@ -450,7 +450,7 @@ HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestUInt32009, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -463,7 +463,7 @@ HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
uint32_t val = 0;
@@ -483,7 +483,7 @@ HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestUInt16010, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -496,7 +496,7 @@ HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
uint16_t val = 0;
@@ -516,7 +516,7 @@ HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestUInt8011, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -529,7 +529,7 @@ HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level1)
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
uint8_t val = 0;
@@ -549,7 +549,7 @@ HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestString012, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestString012, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -561,12 +561,11 @@ HWTEST_F(SBufTest, SbufTestString012, TestSize.Level1)
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
for (int j = 0; j < loop; ++j) {
const char *readStr = HdfSbufReadString(readBuf);
ASSERT_NE(readStr, nullptr);
ASSERT_EQ(std::string(readStr), str);
}
HdfSBufRecycle(readBuf);
@@ -579,7 +578,7 @@ HWTEST_F(SBufTest, SbufTestString012, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestNullString013, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -589,7 +588,7 @@ HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level1)
ASSERT_EQ(true, ret);
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_NE((size_t)0, dataSize);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
auto val = HdfSbufReadString(readBuf);
ASSERT_EQ(nullptr, val);
@@ -607,7 +606,7 @@ HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestBuffer014, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -619,7 +618,7 @@ HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level1)
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
for (int j = 0; j < loop; ++j) {
@@ -640,7 +639,7 @@ HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestNullBuffer015, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -650,7 +649,7 @@ HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level1)
ASSERT_EQ(true, ret);
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_NE((size_t)0, dataSize);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
const uint8_t *buffVal = nullptr;
uint32_t buffLen = 0;
@@ -673,7 +672,7 @@ HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
HWTEST_F(HdfSBufTest, SbufTestRandomDataSeq016, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -683,7 +682,7 @@ HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
bool ret = PushDataSequence(sBuf);
ASSERT_EQ(true, ret);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
ASSERT_NE(readBuf, nullptr);
ret = PullDataSequence(readBuf);
@@ -698,7 +697,7 @@ HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestRandomRWDataSeq017, TestSize.Level0)
HWTEST_F(HdfSBufTest, SbufTestRandomRWDataSeq017, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -731,7 +730,7 @@ HWTEST_F(SBufTest, SbufTestRandomRWDataSeq017, TestSize.Level0)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestSbufMove018, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestSbufMove018, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
@@ -768,7 +767,7 @@ HWTEST_F(SBufTest, SbufTestSbufMove018, TestSize.Level1)
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestSbufMoveHalf019, TestSize.Level1)
HWTEST_F(HdfSBufTest, SbufTestSbufMoveHalf019, TestSize.Level1)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_SEC_H
#define HDF_SEC_H
#if defined(__KERNEL__)
#include <linux/ioctl.h>
#include <linux/types.h>
#else
#include <sys/ioctl.h>
#include <stddef.h>
#include <stdint.h>
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
#define DEVICE_HDF_SECURE_NAME "hdf_secure"
#define HDF_SECURE_MAGIC 'S'
/* event commands */
#define HDF_SECURE_SET_INFO _IO(HDF_SECURE_MAGIC, 0x1)
#define HDF_SECURE_SET_CURRENT_ID _IO(HDF_SECURE_MAGIC, 0x2)
#define HDF_SECURE_DELETE_INFO _IO(HDF_SECURE_MAGIC, 0x3)
#define HDF_DECLARE_BITMAP(name, bits) \
uint64_t name[HDF_BITS_TO_LONGS(bits)]
#define HDF_BITS_TO_LONGS(nr) HDF_DIV_ROUND_UP(nr, HDF_BITS_PER_BYTE * sizeof(uint64_t))
#define HDF_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define HDF_BITS_PER_BYTE 8
#define SECMAP_MAX_SIZE 64
#define ID_MAX_SIZE 65
struct SecInfo {
char secId[ID_MAX_SIZE];
HDF_DECLARE_BITMAP(secMap, SECMAP_MAX_SIZE);
};
uint32_t hdf_permission_check(uint8_t type);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* HDF_SEC_H */
+12
View File
@@ -12,9 +12,21 @@
#include "hdf_device_desc.h"
#include "hdf_slist.h"
enum {
HDF_SERVICE_UNUSABLE,
HDF_SERVICE_USABLE,
};
enum {
HDF_DEV_LOCAL_SERVICE,
HDF_DEV_REMOTE_SERVICE,
};
struct HdfDeviceInfo {
struct HdfSListNode node;
bool isDynamic;
uint16_t status;
uint16_t deviceType;
uint16_t hostId;
uint16_t deviceId;
uint16_t policy;
+2 -2
View File
@@ -20,8 +20,8 @@ extern "C" {
#define DEV_MGR_NODE "dev_mgr"
#define MAX_MODE_SIZE 0777
#define DEV_NODE_PATH_MODE 0755
#define HDF_WRITE_READ _IOWR('b', 1, struct HdfSBuf)
#define HDF_READ_DEV_EVENT _IOR('b', 2, struct HdfSBuf)
#define HDF_WRITE_READ _IOWR('b', 1, struct HdfSBuf*)
#define HDF_READ_DEV_EVENT _IOR('b', 2, struct HdfSBuf*)
#define HDF_LISTEN_EVENT_START _IO('b', 3)
#define HDF_LISTEN_EVENT_STOP _IO('b', 4)
#define HDF_LISTEN_EVENT_WAKEUP _IO('b', 5)
+2
View File
@@ -19,6 +19,8 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
}
deviceInfo->isDynamic = false;
deviceInfo->hostId = 0;
deviceInfo->status = HDF_SERVICE_UNUSABLE;
deviceInfo->deviceType = HDF_DEV_LOCAL_SERVICE;
deviceInfo->deviceId = 0;
deviceInfo->policy = SERVICE_POLICY_INVALID;
deviceInfo->priority = 0;
-1
View File
@@ -27,4 +27,3 @@ void DevSvcRecordDelete(struct HdfSListNode *listEntry)
OsalMemFree(listEntry);
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 74 KiB

+5 -5
View File
@@ -10,12 +10,12 @@
* @addtogroup DriverConfig
* @{
*
* @brief Defines an API for HDF driver developers to read driver configuration information.
* @brief Defines APIs for HDF driver developers to read driver configuration information.
*
* During version compilation of the device resource source file defined by developers, the compilation tool
* (for example, the compilation tool of the HCS file is hc-gen) generates bytecodes. When the HDF starts,
* it transfers the bytecode memory to the <b>DriverConfig</b> module. The <b>DriverConfig</b> module converts
* the bytecodes into a configuration tree and provides an API for developers to query the tree.
* the bytecodes into a configuration tree and provides APIs for developers to query the tree.
*
* @since 1.0
* @version 1.0
@@ -24,7 +24,7 @@
/**
* @file device_resource_if.h
*
* @brief Declares the API for querying the configuration tree.
* @brief Declares the APIs for querying the configuration tree.
*
* @since 1.0
* @version 1.0
@@ -142,7 +142,7 @@ struct DeviceResourceIface {
int32_t (*GetUint8ArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
uint8_t *value, uint8_t def);
/**
* @brief Obtains the values of a <b>Uint8</b> array attribute of a configuration tree node.
* @brief Obtains the value of a <b>Uint8</b> array attribute of a configuration tree node.
*
* @param node Indicates the pointer to the configuration tree node.
* @param attrName Indicates the pointer to the name of the array attribute.
@@ -443,5 +443,5 @@ struct DeviceResourceIface *DeviceResourceGetIfaceInstance(DeviceResourceType ty
#endif
#endif /* __cplusplus */
#endif // DEVICE_RESOURCE_IF_H
#endif /* DEVICE_RESOURCE_IF_H */
/** @} */
+1 -16
View File
@@ -10,7 +10,7 @@
* @addtogroup Core
* @{
*
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
* @brief Provides Hardware Driver Foundation (HDF) APIs.
*
* The HDF implements driver framework capabilities such as driver loading, service management,
* and driver message model. You can develop drivers based on the HDF.
@@ -177,21 +177,6 @@ struct SubscriberCallback {
int32_t (*OnServiceConnected)(struct HdfDeviceObject *deviceObject, const struct HdfObject *service);
};
/**
* @brief Defines the power management functions provided by the HDF for the driver.
*
* To use the power management mechanism provided by the HDF, implement operations of <b>IPowerEventListener</b> and
* invoke {@linkHdfDeviceRegisterPowerListener} to register the operations with the HDF.
*
* @since 1.0
*/
struct IPowerEventListener {
/** Wakes up the driver device. The driver developer implements the operation. */
void (*Resume)(struct HdfDeviceObject *deviceObject);
/** Hibernates the driver device. The driver developer implements the operation. */
void (*Suspend)(struct HdfDeviceObject *deviceObject);
};
/**
* @brief Defines the entry structure of the driver in the HDF.
*
+1 -1
View File
@@ -10,7 +10,7 @@
* @addtogroup Core
* @{
*
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
* @brief Provides Hardware Driver Foundation (HDF) APIs.
*
* The HDF implements driver framework capabilities such as driver loading, service management,
* and driver message model. You can develop drivers based on the HDF.
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_POWER_MANAGEMENT_H
#define HDF_POWER_MANAGEMENT_H
#include "hdf_device_desc.h"
#include "osal_sysevent.h"
enum PowerManagementMode {
HDF_POWER_SYS_CTRL,
HDF_POWER_DYNAMIC_CTRL,
HDF_POWER_MODE_MAX,
};
/**
* @brief Defines the power management functions provided by the HDF for the driver.
*
* To use the power management mechanism provided by the HDF, implement operations of <b>IPowerEventListener</b> and
* invoke {@linkHdfDeviceRegisterPowerListener} to register the operations with the HDF.
*
* @since 1.0
*/
struct IPowerEventListener {
int (*DozeResume)(struct HdfDeviceObject *deviceObject);
int (*DozeSuspend)(struct HdfDeviceObject *deviceObject);
/** Wakes up the driver device. The driver developer implements the operation. */
int (*Resume)(struct HdfDeviceObject *deviceObject);
/** Hibernates the driver device. The driver developer implements the operation. */
int (*Suspend)(struct HdfDeviceObject *deviceObject);
};
static inline bool HdfPmIsWakeEvent(int sysEvent)
{
return sysEvent >= KEVENT_POWER_RESUME && sysEvent <= KEVENT_POWER_DISPLAY_ON;
}
int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject);
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject);
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode);
#endif /* HDF_POWER_MANAGEMENT_H */
+18 -10
View File
@@ -87,6 +87,23 @@ struct OsalFwBlock {
*/
int32_t OsalRequestFirmware(struct OsalFirmware *fw, const char *fwName, void *device);
/**
* @brief Sets the offset for reading a firmware file to implement random access to the firmware file.
*
* @param fw Indicates the pointer to the firmware file {@link OsalFirmware}.
* @param offset Indicates the offset where the firmware content is to read.
*
* @return Returns a value listed below: \n
* HDF_STATUS | Description
* ----------------------| -----------------------
* HDF_SUCCESS | The operation is successful.
* HDF_ERR_INVALID_PARAM | Invalid parameter.
*
* @since 1.0
* @version 1.0
*/
int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
/**
* @brief Reads a firmware file.
*
@@ -103,7 +120,7 @@ int32_t OsalRequestFirmware(struct OsalFirmware *fw, const char *fwName, void *d
* @since 1.0
* @version 1.0
*/
int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
int32_t OsalReadFirmware(struct OsalFirmware *fw, struct OsalFwBlock *block);
/**
* @brief Releases a firmware file.
@@ -122,15 +139,6 @@ int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
* @since 1.0
* @version 1.0
*/
int32_t OsalReadFirmware(struct OsalFirmware *fw, struct OsalFwBlock *block);
/**
* Release firmware resource
*
* @param : fw Firmware parameter, see detail in OsalFirmware
* block Firmware data block, see detail in hdf_FWBlock
* @return : true or false
*/
int32_t OsalReleaseFirmware(struct OsalFirmware *fw);
#ifdef __cplusplus
+2
View File
@@ -37,6 +37,8 @@
extern "C" {
#endif /* __cplusplus */
#define OSAL_WAIT_FOREVER 0xFFFFFFFF
/**
* @brief Describes a semaphore.
*/
+6
View File
@@ -194,6 +194,12 @@ static inline void DListMerge(struct DListHead *list, struct DListHead *head)
&(pos)->member != (head); \
(pos) = CONTAINER_OF((pos)->member.next, type, member))
#define DLIST_FOR_EACH_ENTRY_REVERSE(pos, head, type, member) \
for ((pos) = CONTAINER_OF((head)->prev, type, member); \
&(pos)->member != (head); \
(pos) = CONTAINER_OF((pos)->member.prev, type, member))
/**
* @brief Traverses all nodes in a doubly linked list.
* This function is used to delete the nodes pointed to by <b>pos</b> during traversal.
+5 -5
View File
@@ -32,8 +32,8 @@
* @version 1.0
*/
#ifndef __HDF_WIFI_EVENT_H__
#define __HDF_WIFI_EVENT_H__
#ifndef HDF_WIFI_EVENT_H
#define HDF_WIFI_EVENT_H
#include "hdf_wifi_cmd.h"
#include "wifi_mac80211_ops.h"
@@ -52,7 +52,7 @@ extern "C" {
* @version 1.0
*/
struct RateInfo {
uint8_t flags; /**< Flag field, used to indicate a specific rate transmission type of 802.11n */
uint8_t flags; /**< Flag, used to indicate a specific rate transmission type of 802.11n */
uint8_t mcs; /**< Modulation and Coding Scheme (MCS) index of the HT/VHT/HE rate */
uint16_t legacy; /**< 100 kbit/s bit rate defined in 802.11a/b/g */
uint8_t nss; /**< Number of streams (for VHT and HE only) */
@@ -268,7 +268,7 @@ struct Ieee80211Mgmt {
struct ScannedBssInfo {
int32_t signal; /**< Signal strength */
int16_t freq; /**< Center frequency of the channel where the BSS is located */
uint8_t arry[2]; /**< Reserved */
uint8_t array[2]; /**< Reserved */
uint32_t mgmtLen; /**< Management frame length */
struct Ieee80211Mgmt *mgmt; /**< Start address of the management frame */
};
@@ -482,5 +482,5 @@ int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus);
#endif
#endif
#endif /* __HDF_WIFI_EVENT_H__ */
#endif /* HDF_WIFI_EVENT_H */
/** @} */
+1 -1
View File
@@ -113,7 +113,7 @@ struct WifiModule* HdfWlanGetModule(void);
struct HdfWlanDevice *HdfWlanGetWlanDevice(uint8_t chipId);
/**
* @brief Send broadcast event.
* @brief Sends a broadcast event.
*
* @param id Indicates the ID of the event to send.
* @param data Indicates the pointer to the event information.
+5 -5
View File
@@ -387,7 +387,7 @@ struct TcpHeader {
uint16_t sPort; /**< Source port number */
uint16_t dPort; /**< Destination port number */
uint32_t seqNum; /**< Sequence number */
uint32_t ackNum; /**< Acknowledgement number */
uint32_t ackNum; /**< Acknowledgment number */
uint8_t offset; /**< Header length */
uint8_t flags; /**< Flags */
uint16_t window; /**< Window size */
@@ -465,7 +465,7 @@ typedef struct NetDevice {
char name[IFNAMSIZ]; /**< Network device name {@link IFNAMSIZ} */
NetLinkType LinkLayerType; /**< Data link layer type */
IfType funType; /**< Network port type */
char macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */
unsigned char macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */
uint32_t flags; /**< Network port status */
uint32_t mtu; /**< Maximum transmission unit */
int32_t watchdogTime; /**< Watchdog duration */
@@ -496,12 +496,12 @@ struct NetDeviceInterFace {
void (*deInit)(struct NetDevice *netDev); /**< Deinitializes a network device to be delete. */
int32_t (*open)(struct NetDevice *netDev); /**< Opens the data link layer. */
int32_t (*stop)(struct NetDevice *netDev); /**< Closes the data link layer. */
NetDevTxResult (*xmit)(struct NetDevice *netDev, NetBuf *netBuff); /**< Sends data. */
NetDevTxResult (*xmit)(struct NetDevice *netDev, NetBuf *netBuff); /**< Sends data. */
int32_t (*ioctl)(struct NetDevice *netDev, IfReq *req, int32_t cmd); /**< Used for the control command word. */
int32_t (*setMacAddr)(struct NetDevice *netDev, void *addr); /**< Sets the MAC address. */
struct NetDevStats *(*getStats)(struct NetDevice *netDev); /**< Obtains the statistics. */
void (*setNetIfStatus)(struct NetDevice *netDev, NetIfStatus status); /**< Sets the network port status. */
uint16_t (*selectQueue)(struct NetDevice *netDev, NetBuf *netBuff);/**< Selects a priority queue. */
uint16_t (*selectQueue)(struct NetDevice *netDev, NetBuf *netBuff); /**< Selects a priority queue. */
uint32_t (*netifNotify)(struct NetDevice *netDev, NetDevNotify *notify); /**< Notifies the network port status. */
int32_t (*changeMtu)(struct NetDevice *netDev, int32_t newMtu); /**< Changes the maximum number of
* transmission units.
@@ -658,7 +658,7 @@ int32_t NetIfSetAddr(const struct NetDevice *netDevice, const IpV4Addr *ipAddr,
* @brief Notifies the network layer of the network port state.
*
* @param netDevice Indicates the pointer to the network device obtained during initialization.
* @paramstatus Indicates the network port state, as enumerated in {@link NetIfSatus}.
* @param status Indicates the network port state, as enumerated in {@link NetIfSatus}.
* @param status Indicates the network port state, as enumerated in {@link NetIfSatus}.
*
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
+1 -1
View File
@@ -62,7 +62,7 @@ struct BusDev;
* @version 1.0
*/
enum WifiMainFeatureType {
HDF_WIFI_FEATURE_AP, /**< AP */
HDF_WIFI_FEATURE_AP, /**< Access point (AP) */
HDF_WIFI_FEATURE_STA, /**< Station */
HDF_WIFI_FEATURE_P2P, /**< Peer-to-peer (P2P) */
HDF_WIFI_FEATURE_NAN, /**< Neighbor Awareness Networking (NAN) */
+6 -6
View File
@@ -32,8 +32,8 @@
* @version 1.0
*/
#ifndef _WIFI_MAC80211_OPS_H_
#define _WIFI_MAC80211_OPS_H_
#ifndef WIFI_MAC80211_OPS_H
#define WIFI_MAC80211_OPS_H
#include "net_device.h"
#include "hdf_wifi_cmd.h"
@@ -440,9 +440,9 @@ struct WlanAPConf {
struct WlanHwCapability {
void (*Release)(struct WlanHwCapability *self); /**< Function for releasing the hardware capability */
struct WlanBand *bands[IEEE80211_NUM_BANDS]; /**< Frequency bands */
uint16_t htCapability; /**< High-throughput (HT) capability */
uint16_t supportedRateCount;/**< Number of supported rates */
uint16_t *supportedRates; /**< An array of supported rates in 100 kbit/s */
uint16_t htCapability; /**< High-throughput (HT) capability */
uint16_t supportedRateCount; /**< Number of supported rates */
uint16_t *supportedRates; /**< An array of supported rates in 100 kbit/s */
};
/**
@@ -767,5 +767,5 @@ struct HdfMac80211APOps {
int32_t (*GetAssociatedStasInfo)(NetDevice *netDev, WifiStaInfo *staInfo, uint32_t num);
};
#endif // _WIFI_MAC80211_OPS_H_
#endif // WIFI_MAC80211_OPS_H
/** @} */
+1 -1
View File
@@ -206,7 +206,7 @@ int16_t InitWifiModule(struct WifiModule *module, const struct HdfConfigWlanModu
#define RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipOps, opsName) \
do { \
if ((chipOps) == NULL ||(chipOps)->opsName == NULL) { \
if ((chipOps) == NULL || (chipOps)->opsName == NULL) { \
HDF_LOGE("macOps" #opsName "not implement"); \
return HDF_ERR_INVALID_OBJECT; \
} \
+200 -107
View File
@@ -13,133 +13,141 @@
#define OFFSET_TWO_BYTE 16
struct DispOperations *g_dispOps = NULL;
static struct PlatformOps *g_platformOps = NULL;
int32_t DispRegister(struct DispOperations *ops)
int32_t PlatformRegister(struct PlatformOps *ops)
{
if (g_dispOps == NULL) {
g_dispOps = ops;
if (g_platformOps == NULL) {
g_platformOps = ops;
HDF_LOGI("%s: disp ops register success", __func__);
return HDF_SUCCESS;
}
HDF_LOGD("%s: disp ops registered", __func__);
HDF_LOGD("%s: success", __func__);
return HDF_FAILURE;
}
static struct PlatformOps *GetPlatformOps(void)
{
return g_platformOps;
}
static int32_t InitDisp(uint32_t devId);
static int32_t DispOn(uint32_t devId);
static int32_t DispOff(uint32_t devId);
static int32_t SetDispBacklight(uint32_t devId, uint32_t level);
static int32_t GetDispInfo(uint32_t devId, struct DispInfo *info);
struct DispOperations *GetDispOps(void)
{
return g_dispOps;
static struct DispOperations dispOps = {
.init = InitDisp,
.on = DispOn,
.off = DispOff,
.setBacklight = SetDispBacklight,
.getDispInfo = GetDispInfo,
};
return &dispOps;
}
#ifdef __KERNEL__
EXPORT_SYMBOL(GetDispOps);
#endif
static int32_t InitDisp(uint32_t devId)
{
return 0;
}
static int32_t DispOn(uint32_t devId)
{
int32_t ret;
struct DispOperations *ops = NULL;
int32_t ret = HDF_FAILURE;
struct PlatformOps *ops = NULL;
ops = GetDispOps();
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
return HDF_FAILURE;
}
if (ops->on != NULL) {
ops = GetPlatformOps();
if (ops && ops->on) {
ret = ops->on(devId);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: ops on failed", __func__);
return HDF_FAILURE;
}
}
return HDF_SUCCESS;
return ret;
}
static int32_t DispOff(uint32_t devId)
{
int32_t ret;
struct DispOperations *ops = NULL;
int32_t ret = HDF_FAILURE;
struct PlatformOps *ops = NULL;
ops = GetDispOps();
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
return HDF_FAILURE;
}
if (ops->off != NULL) {
ops = GetPlatformOps();
if (ops && ops->off) {
ret = ops->off(devId);
}
return ret;
}
static int32_t SetDispBacklight(uint32_t devId, uint32_t level)
{
int32_t ret = HDF_FAILURE;
struct PanelStatus *panelStatus = NULL;
struct PanelInfo *info = GetPanelInfo(devId);
if (info == NULL) {
HDF_LOGE("%s:GetPanelInfo failed", __func__);
return HDF_FAILURE;
}
if (level > info->blk.maxLevel) {
level = info->blk.maxLevel;
} else if (level < info->blk.minLevel && level != 0) {
level = info->blk.minLevel;
}
struct PlatformOps *ops = GetPlatformOps();
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
return HDF_FAILURE;
}
if (ops->setBacklight != NULL) {
ret = ops->setBacklight(devId, level);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: ops off failed", __func__);
HDF_LOGE("%s: setBacklight failed", __func__);
return HDF_FAILURE;
}
}
if (ret == HDF_SUCCESS) {
panelStatus = GetPanelStatus(devId);
if (!panelStatus) {
HDF_LOGE("%s: panelStatus is null", __func__);
return HDF_FAILURE;
}
panelStatus->currLevel = level;
}
HDF_LOGI("%s:level = %u", __func__, level);
return HDF_SUCCESS;
}
static int32_t DispInit(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
static int32_t GetDispInfo(uint32_t devId, struct DispInfo *info)
{
(void)device;
(void)rspData;
int32_t ret;
uint32_t devId = 0;
struct PlatformOps *ops = NULL;
if (reqData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint32(reqData, &devId)) {
HDF_LOGE("%s: HdfSbufReadBuffer failed", __func__);
if (info == NULL) {
HDF_LOGE("%s:info is null", __func__);
return HDF_FAILURE;
}
struct DispOperations *ops = NULL;
ops = GetDispOps();
ops = GetPlatformOps();
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
return HDF_FAILURE;
}
if (ops->init != NULL) {
ret = ops->init(devId);
if (ret) {
HDF_LOGE("%s: init failed", __func__);
return HDF_FAILURE;
}
}
return HDF_SUCCESS;
}
static int32_t GetDispInfo(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
(void)device;
(void)rspData;
uint32_t devId = 0;
struct DispInfo info;
struct DispOperations *ops = NULL;
if (reqData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint32(reqData, &devId)) {
HDF_LOGE("%s: HdfSbufReadBuffer failed", __func__);
return HDF_FAILURE;
}
ops = GetDispOps();
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
return HDF_FAILURE;
}
(void)memset_s(&info, sizeof(struct DispInfo), 0, sizeof(struct DispInfo));
if (ops->getDispInfo != NULL) {
if (ops->getDispInfo(devId, &info)) {
if (ops->getDispInfo(devId, info)) {
HDF_LOGE("%s: getDispInfo failed", __func__);
return HDF_FAILURE;
}
}
if (!HdfSbufWriteBuffer(rspData, &info, sizeof(struct DispInfo)) != 0) {
HDF_LOGE("%s: copy info failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t SetPowerMode(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
static int32_t SetPowerStatus(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
uint32_t para = 0;
int32_t ret = HDF_FAILURE;
struct PanelStatus *panelStatus = NULL;
(void)device;
(void)rspData;
@@ -151,20 +159,58 @@ static int32_t SetPowerMode(struct HdfDeviceObject *device, struct HdfSBuf *reqD
return HDF_FAILURE;
}
uint32_t devId = (para >> OFFSET_TWO_BYTE) & 0xffff;
uint32_t mode = para & 0xffff;
if (mode == DISP_ON) {
return DispOn(devId);
uint32_t powerStatus = para & 0xffff;
switch (powerStatus) {
case POWER_STATUS_ON:
ret = DispOn(devId);
break;
case POWER_STATUS_OFF:
ret = DispOff(devId);
break;
default:
HDF_LOGE("%s: not support powerStatus: %d", __func__, powerStatus);
break;
}
if (mode == DISP_OFF) {
return DispOff(devId);
if (ret == HDF_SUCCESS) {
panelStatus = GetPanelStatus(devId);
if (panelStatus == NULL) {
HDF_LOGE("%s: panelStatus is null", __func__);
return HDF_FAILURE;
}
panelStatus->powerStatus = powerStatus;
}
HDF_LOGE("not support mode:%u", mode);
return HDF_FAILURE;
return ret;
}
static int32_t GetPowerStatus(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
uint32_t devId = 0;
struct PanelStatus *panelStatus = NULL;
(void)device;
if (reqData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint32(reqData, &devId)) {
HDF_LOGE("%s: HdfSbufReadBuffer failed", __func__);
return HDF_FAILURE;
}
panelStatus = GetPanelStatus(devId);
if (!panelStatus) {
HDF_LOGE("%s: panelStatus is null", __func__);
return HDF_FAILURE;
}
if (!HdfSbufWriteUint32(rspData, panelStatus->powerStatus)) {
HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t SetBacklight(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
int32_t ret;
(void)device;
(void)rspData;
if (reqData == NULL) {
@@ -177,37 +223,67 @@ static int32_t SetBacklight(struct HdfDeviceObject *device, struct HdfSBuf *reqD
}
uint32_t devId = (para >> OFFSET_TWO_BYTE) & 0xffff;
uint32_t level = para & 0xffff;
struct PanelInfo *info = GetPanelInfo(devId);
if (info == NULL) {
HDF_LOGE("%s:GetPanelInfo failed", __func__);
ret = SetDispBacklight(devId, level);
return ret;
}
static int32_t GetBacklight(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
uint32_t devId = 0;
struct PanelStatus *panelStatus = NULL;
(void)device;
if (reqData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint32(reqData, &devId)) {
HDF_LOGE("%s: HdfSbufReadBuffer failed", __func__);
return HDF_FAILURE;
}
if (level > info->blk.maxLevel) {
level = info->blk.maxLevel;
} else if (level < info->blk.minLevel && level != 0) {
level = info->blk.minLevel;
}
struct DispOperations *ops = GetDispOps();
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
panelStatus = GetPanelStatus(devId);
if (!panelStatus) {
HDF_LOGE("%s: panelStatus is null", __func__);
return HDF_FAILURE;
}
if (ops->setBacklight != NULL) {
ret = ops->setBacklight(devId, level);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: setBacklight failed", __func__);
return HDF_FAILURE;
}
if (!HdfSbufWriteUint32(rspData, panelStatus->currLevel)) {
HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t GetInfo(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
(void)device;
(void)rspData;
uint32_t devId = 0;
struct DispInfo info;
if (reqData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint32(reqData, &devId)) {
HDF_LOGE("%s: HdfSbufReadBuffer failed", __func__);
return HDF_FAILURE;
}
(void)memset_s(&info, sizeof(struct DispInfo), 0, sizeof(struct DispInfo));
if (GetDispInfo(devId, &info) != HDF_SUCCESS) {
HDF_LOGE("%s: GetDispInfo failed", __func__);
return HDF_FAILURE;
}
if (!HdfSbufWriteBuffer(rspData, &info, sizeof(struct DispInfo)) != 0) {
HDF_LOGE("%s: copy info failed", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s:level = %u", __func__, level);
return HDF_SUCCESS;
}
DispCmdHandle g_dispCmdHandle[] = {
DispInit,
GetDispInfo,
SetPowerMode,
GetPowerStatus,
GetInfo,
SetPowerStatus,
SetBacklight,
GetBacklight,
};
static int32_t DispCmdProcess(struct HdfDeviceObject *device, int32_t cmd, struct HdfSBuf *reqData,
@@ -253,10 +329,27 @@ static int HdfDispBind(struct HdfDeviceObject *dev)
static int32_t HdfDispEntryInit(struct HdfDeviceObject *object)
{
int32_t ret;
int32_t i;
struct PlatformOps *ops = GetPlatformOps();
if (object == NULL) {
HDF_LOGE("%s: object is null!", __func__);
return HDF_FAILURE;
}
if (ops == NULL) {
HDF_LOGE("%s: ops is null", __func__);
return HDF_FAILURE;
}
if (ops->init != NULL) {
for (i = 0; i < g_numRegisteredPanel; i++) {
ret = ops->init(i);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: init failed", __func__);
return HDF_FAILURE;
}
}
}
return HDF_SUCCESS;
}
+10 -1
View File
@@ -45,11 +45,20 @@ struct DispOperations {
int32_t (*getDispInfo)(uint32_t devId, struct DispInfo *info);
};
struct PlatformOps {
int32_t (*init)(uint32_t devId);
int32_t (*on)(uint32_t devId);
int32_t (*off)(uint32_t devId);
int32_t (*setBacklight)(uint32_t devId, uint32_t level);
int32_t (*getDispInfo)(uint32_t devId, struct DispInfo *info);
};
enum PowerMode {
DISP_ON,
DISP_OFF,
};
int32_t DispRegister(struct DispOperations *ops);
int32_t PlatformRegister(struct PlatformOps *ops);
struct PanelInfo *GetPanelInfo(int32_t index);
struct PanelStatus *GetPanelStatus(int32_t index);
#endif /* HDF_DISP_H */
+8 -5
View File
@@ -6,6 +6,7 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "hi35xx_disp.h"
#include <securec.h>
#include "hdf_base.h"
#include "hdf_device_desc.h"
@@ -14,7 +15,6 @@
#include "lcd_abs_if.h"
#include "osal_io.h"
#include "pwm_if.h"
#include "hi35xx_disp.h"
#define TRANSFORM_KILO 1000
#define TRANSFORM_MILL 1000000
@@ -186,10 +186,13 @@ static uint32_t CalcDataRate(struct PanelInfo *info)
} else {
bitClk = bitNum / TRANSFORM_MILL + 1;
}
if (!info->mipi.lane) {
return HDF_FAILURE;
}
if ((bitClk % info->mipi.lane) == 0) {
return bitClk / info->mipi.lane;
}
return bitClk / info->mipi.lane + 1;
return (bitClk / info->mipi.lane) + 1;
}
static int32_t MipiDsiInit(struct PanelInfo *info)
@@ -225,7 +228,7 @@ static int32_t MipiDsiInit(struct PanelInfo *info)
HDF_LOGE("%s:MipiDsiSetCfg failed", __func__);
}
MipiDsiClose(mipiHandle);
HDF_LOGI("%s:pixelClk = %d, phyDataRate = %d", __func__, cfg.pixelClk, cfg.phyDataRate);
HDF_LOGI("%s:pixelClk = %d, phyDataRate = %u", __func__, cfg.pixelClk, cfg.phyDataRate);
return ret;
}
@@ -425,7 +428,7 @@ static int32_t Hi35xxSetBacklight(uint32_t devId, uint32_t level)
return HDF_SUCCESS;
}
struct DispOperations g_hi35xxOps = {
struct PlatformOps g_hi35xxOps = {
.init = Hi35xxInit,
.on = Hi35xxOn,
.off = Hi35xxOff,
@@ -439,7 +442,7 @@ static int32_t Hi35xxEntryInit(struct HdfDeviceObject *object)
HDF_LOGE("%s: param is null!", __func__);
return HDF_FAILURE;
}
return DispRegister(&g_hi35xxOps);
return PlatformRegister(&g_hi35xxOps);
}
struct HdfDriverEntry g_hi35xxDevEntry = {
+14 -4
View File
@@ -6,15 +6,15 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "lcd_abs_if.h"
#include <asm/io.h>
#include "hdf_device_desc.h"
#include "osal.h"
#include "lcd_abs_if.h"
/* support max panel number */
#define PANEL_MAX 2
static struct PanelData *g_panelData[PANEL_MAX];
static int32_t numRegisteredPanel;
int32_t g_numRegisteredPanel;
int32_t PanelDataRegister(struct PanelData *data)
{
@@ -24,10 +24,10 @@ int32_t PanelDataRegister(struct PanelData *data)
HDF_LOGE("%s: panel data is null", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (numRegisteredPanel == PANEL_MAX) {
if (g_numRegisteredPanel == PANEL_MAX) {
return HDF_FAILURE;
}
numRegisteredPanel++;
g_numRegisteredPanel++;
for (i = 0; i < PANEL_MAX; i++) {
if (g_panelData[i] == NULL) {
break;
@@ -60,3 +60,13 @@ struct PanelInfo *GetPanelInfo(int32_t index)
return g_panelData[index]->info;
}
struct PanelStatus *GetPanelStatus(const int32_t index)
{
if ((index >= PANEL_MAX) || index < 0) {
return NULL;
}
if (g_panelData[index] == NULL) {
return NULL;
}
return g_panelData[index]->status;
}
+16 -1
View File
@@ -26,7 +26,7 @@ enum BacklightType {
BLK_MIPI,
};
/* output timming */
/* output timing */
enum IntfSync {
OUTPUT_USER = 0, /* User timing */
OUTPUT_PAL, /* PAL standard */
@@ -85,6 +85,14 @@ struct MipiDsiDesc {
enum DsiOutFormat format;
};
enum PowerStatus {
POWER_STATUS_ON, /* The power status is on */
POWER_STATUS_STANDBY, /* The power status is standby */
POWER_STATUS_SUSPEND, /* The power status is suspend */
POWER_STATUS_OFF, /* The power status is off */
POWER_STATUS_BUTT
};
struct BlkDesc {
uint32_t type;
uint32_t minLevel;
@@ -114,14 +122,21 @@ struct PanelInfo {
struct PwmCfg pwm;
};
struct PanelStatus {
enum PowerStatus powerStatus;
uint32_t currLevel;
};
struct PanelData {
struct PanelInfo *info;
struct PanelStatus *status;
int32_t (*init)(void);
int32_t (*on)(void);
int32_t (*off)(void);
int32_t (*setBacklight)(uint32_t level);
};
extern int32_t g_numRegisteredPanel;
int32_t PanelDataRegister(struct PanelData *data);
#endif /* LCD_ABS_IF_H */
@@ -45,6 +45,8 @@ static int32_t ParseDsiCmd(struct PanelCmd *cmd, int32_t count, uint8_t *array,
return HDF_FAILURE;
}
int32_t ret;
int32_t i;
int32_t num = 0;
cmd->count = count;
cmd->dsiCmd = dsiCmd;
uint8_t *tmpArray = array;
@@ -56,6 +58,9 @@ static int32_t ParseDsiCmd(struct PanelCmd *cmd, int32_t count, uint8_t *array,
tmpCmd->payload = (uint8_t *)OsalMemCalloc(tmpCmd->dataLen * sizeof(uint8_t));
if (tmpCmd->payload == NULL) {
HDF_LOGE("%s: OsalMemCalloc failed", __func__);
for (i = 0; i < num; i++) {
OsalMemFree(dsiCmd[i]->payload);
}
OsalMemFree(array);
OsalMemFree(dsiCmd);
cmd->dsiCmd = NULL;
@@ -63,9 +68,12 @@ static int32_t ParseDsiCmd(struct PanelCmd *cmd, int32_t count, uint8_t *array,
return HDF_FAILURE;
}
ret = memcpy_s(tmpCmd->payload, tmpCmd->dataLen, &tmpArray[DSI_CMD_HEAD], tmpCmd->dataLen);
ret = memcpy_s(tmpCmd->payload, tmpCmd->dataLen, &tmpArray[DSI_CMD_HEAD], DSI_CMD_HEAD);
if (ret != EOK) {
HDF_LOGE("%s: memcpy_s failed, ret %d", __func__, ret);
for (i = 0; i < num; i++) {
OsalMemFree(dsiCmd[i]->payload);
}
OsalMemFree(array);
OsalMemFree(dsiCmd);
cmd->dsiCmd = NULL;
@@ -76,6 +84,7 @@ static int32_t ParseDsiCmd(struct PanelCmd *cmd, int32_t count, uint8_t *array,
tmpArray += DSI_CMD_HEAD + tmpCmd->dataLen;
tmpCmd++;
count--;
num++;
len -= DSI_CMD_HEAD + tmpCmd->dataLen;
}
OsalMemFree(array);
+5 -3
View File
@@ -48,7 +48,7 @@ static int32_t LcdkitInit(void)
struct PanelConfig *panelCfg = GetPanelCfg();
if (panelCfg->info.intfType != MIPI_DSI) {
HDF_LOGE("%s:not support intf: %d", __func__, panelCfg->info.intfType);
HDF_LOGE("%s:not support intf: %u", __func__, panelCfg->info.intfType);
return HDF_FAILURE;
}
ret = PowerInit();
@@ -65,6 +65,8 @@ static int32_t LcdkitInit(void)
if (panelCfg->info.blk.type == BLK_PWM) {
panelCfg->pwmHandle = PwmOpen(panelCfg->info.pwm.dev);
if (panelCfg->pwmHandle == NULL) {
MipiDsiClose(panelCfg->dsiHandle);
panelCfg->dsiHandle = NULL;
HDF_LOGE("%s: PwmOpen failed", __func__);
return HDF_FAILURE;
}
@@ -222,8 +224,8 @@ static int32_t SetBacklightByMipi(uint32_t level)
{
int32_t ret;
struct PanelConfig *panelCfg = GetPanelCfg();
uint8_t payLoad[] = { 0x51, 0x00 };
struct DsiCmdDesc bklCmd = { 0x15, 0, sizeof(payLoad), payLoad };
uint8_t payLoad[] = { 0x51, 0x00 }; // panel backlight cmd
struct DsiCmdDesc bklCmd = { 0x15, 0, sizeof(payLoad), payLoad }; // dsi backlight cmd
if (panelCfg->dsiHandle == NULL) {
HDF_LOGE("%s: dsiHandle is null", __func__);
+15 -9
View File
@@ -28,12 +28,12 @@
#define HORIZONTAL_BACK_PORCH 20
#define HORIZONTAL_FRONT_PORCH 20
#define HORIZONTAL_SYNC_WIDTH 10
#define VERTIACL_BACK_PORCH 14
#define VERTIACL_FRONT_PORCH 16
#define VERTIACL_SYNC_WIDTH 2
#define VERTICAL_BACK_PORCH 14
#define VERTICAL_FRONT_PORCH 16
#define VERTICAL_SYNC_WIDTH 2
#define FRAME_RATE 60
/* panel on commond payload */
/* panel on command payload */
static uint8_t g_payLoad0[] = { 0xF0, 0x5A, 0x5A };
static uint8_t g_payLoad1[] = { 0xF1, 0xA5, 0xA5 };
static uint8_t g_payLoad2[] = { 0xB3, 0x03, 0x03, 0x03, 0x07, 0x05, 0x0D, 0x0F, 0x11, 0x13, 0x09, 0x0B };
@@ -84,7 +84,7 @@ struct DsiCmdDesc g_OnCmd[] = {
{ 0x05, 120, sizeof(g_payLoad20), g_payLoad20 },
};
/* panel off commond payload */
/* panel off command payload */
static uint8_t g_offPayLoad0[] = { 0x28 };
static uint8_t g_offPayLoad1[] = { 0x10 };
struct DsiCmdDesc g_offCmd[] = {
@@ -257,12 +257,12 @@ static struct PanelInfo g_panelInfo = {
.hbp = HORIZONTAL_BACK_PORCH, /* horizontal back porch */
.hfp = HORIZONTAL_FRONT_PORCH, /* horizontal front porch */
.hsw = HORIZONTAL_SYNC_WIDTH, /* horizontal sync width */
.vbp = VERTIACL_BACK_PORCH, /* vertiacl back porch */
.vfp = VERTIACL_FRONT_PORCH, /* vertiacl front porch */
.vsw = VERTIACL_SYNC_WIDTH, /* vertiacl sync width */
.vbp = VERTICAL_BACK_PORCH, /* vertical back porch */
.vfp = VERTICAL_FRONT_PORCH, /* vertical front porch */
.vsw = VERTICAL_SYNC_WIDTH, /* vertical sync width */
.frameRate = FRAME_RATE, /* frame rate */
.intfType = MIPI_DSI, /* panel interface type */
.intfSync = OUTPUT_USER, /* output timming type */
.intfSync = OUTPUT_USER, /* output timing type */
/* mipi config info */
.mipi = { DSI_2_LANES, DSI_VIDEO_MODE, VIDEO_BURST_MODE, FORMAT_RGB_24_BIT },
/* backlight config info */
@@ -270,8 +270,14 @@ static struct PanelInfo g_panelInfo = {
.pwm = { BLK_PWM1, PWM_MAX_PERIOD },
};
static struct PanelStatus g_panelStatus = {
.powerStatus = POWER_STATUS_OFF,
.currLevel = MIN_LEVEL,
};
static struct PanelData g_panelData = {
.info = &g_panelInfo,
.status = &g_panelStatus,
.init = Icn9700Init,
.on = Icn9700On,
.off = Icn9700Off,
+4 -4
View File
@@ -124,24 +124,24 @@ static int32_t LcdResetOn(void)
ret = GpioSetDir(RESET_GPIO, GPIO_DIR_OUT);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioSetDir failed, ret:%d", ret);
HDF_LOGE("set lcd reset dir failed, ret:%d", ret);
return HDF_FAILURE;
}
ret = GpioWrite(RESET_GPIO, GPIO_VAL_HIGH);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioWrite failed, ret:%d", ret);
HDF_LOGE("set lcd reset hi failed, ret:%d", ret);
return HDF_FAILURE;
}
ret = GpioWrite(RESET_GPIO, GPIO_VAL_LOW);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioWrite failed, ret:%d", ret);
HDF_LOGE("set lcd reset how failed, ret:%d", ret);
return HDF_FAILURE;
}
/* delay 10ms */
OsalMSleep(10);
ret = GpioWrite(RESET_GPIO, GPIO_VAL_HIGH);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioWrite failed, ret:%d", ret);
HDF_LOGE("set lcd reset hi after delay failed, ret:%d", ret);
return HDF_FAILURE;
}
/* delay 120ms */
-1
View File
@@ -16,7 +16,6 @@
#define BITS_PER_BYTE 8
#define BITS_PER_WORD 9
#define SPI_MAX_SPEED 115200
#define SYS_WRITEL(addr, value) ((*(volatile unsigned int *)(addr)) = (value))
struct LcdCmd {
uint8_t cmd;
+6
View File
@@ -26,6 +26,12 @@ void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t
{
OsalTimespec time;
EventPackage package = {0};
if (inputDev == NULL) {
HDF_LOGE("%s: parm is null", __func__);
return;
}
package.type = type;
package.code = code;
package.value = value;
-48
View File
@@ -1,48 +0,0 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include <securec.h>
#include "hdf_device_desc.h"
#include "hdf_log.h"
static int32_t HdfHIDDriverInit(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t HdfHIDDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
{
(void)cmd;
if (client == NULL || data == NULL || reply == NULL) {
HDF_LOGE("%s: param is null", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t HdfHIDDriverBind(struct HdfDeviceObject *device)
{
if (device == NULL) {
return HDF_ERR_INVALID_PARAM;
}
static struct IDeviceIoService hidService = {
.Dispatch = HdfHIDDispatch,
};
device->service = &hidService;
return HDF_SUCCESS;
}
struct HdfDriverEntry g_hdfHIDEntry = {
.moduleVersion = 1,
.moduleName = "HDF_HID",
.Bind = HdfHIDDriverBind,
.Init = HdfHIDDriverInit,
};
HDF_INIT(g_hdfHIDEntry);
+164
View File
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include <securec.h>
#include "hdf_device_desc.h"
#include "osal_mem.h"
#include "hdf_log.h"
#include "event_hub.h"
#include "hdf_input_device_manager.h"
#include "hdf_hid_adapter.h"
InputDevice *cachedHid[MAX_INPUT_DEV_NUM];
static bool HaveHidCache(void)
{
if (cachedHid[0] == NULL) {
return false;
}
return true;
}
static void LoadCachedHid(void)
{
int32_t i = 0;
int32_t ret;
if (!HaveHidCache()) {
HDF_LOGI("%s: exit", __func__);
return;
}
while (i < MAX_INPUT_DEV_NUM && cachedHid[i] != NULL) {
ret = RegisterInputDevice(cachedHid[i]);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: add %s failed", __func__, cachedHid[i]->devName);
}
cachedHid[i] = NULL;
i++;
}
}
static InputDevice* HidConstructInputDev(HidInfo info)
{
InputDevice *inputDev = (InputDevice *)OsalMemAlloc(sizeof(InputDevice));
if (inputDev == NULL) {
HDF_LOGE("%s: instance input device failed", __func__);
return NULL;
}
(void)memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice));
inputDev->devType = info.devType;
inputDev->devName = info.devName;
return inputDev;
}
static InputDevice* DoRegisterInputDev(InputDevice* inputDev)
{
int32_t ret;
ret = RegisterInputDevice(inputDev);
if (ret == HDF_SUCCESS) {
return inputDev;
} else {
OsalMemFree(inputDev);
inputDev = NULL;
return NULL;
}
}
static InputDevice* CacheHid(InputDevice* inputDev)
{
int32_t i = 0;
while ((i < MAX_INPUT_DEV_NUM) && (cachedHid[i] != NULL)) {
i++;
}
if (i < MAX_INPUT_DEV_NUM) {
cachedHid[i] = inputDev;
return inputDev;
}
return NULL;
}
static bool InputDriverLoaded(void)
{
InputManager* g_inputManager = GetInputManager();
if ((g_inputManager != NULL) && (g_inputManager->initialized != false)) {
return true;
}
return false;
}
void* HidRegisterHdfInputDev(HidInfo info)
{
InputDevice* inputDev = HidConstructInputDev(info);
if (inputDev == NULL) {
HDF_LOGE("%s: hid construct input Dev failed", __func__);
return NULL;
}
if (InputDriverLoaded()) {
return DoRegisterInputDev(inputDev);
} else {
return CacheHid(inputDev);
}
}
void HidUnregisterHdfInputDev(const void *inputDev)
{
if (inputDev == NULL) {
HDF_LOGE("%s: inputDev is null", __func__);
}
UnregisterInputDevice((InputDevice *)inputDev);
inputDev = NULL;
}
void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value)
{
PushOnePackage((InputDevice *)inputDev, type, code, value);
}
static int32_t HdfHIDDriverInit(struct HdfDeviceObject *device)
{
(void)device;
static bool cachedHidRegistered = false;
if (!cachedHidRegistered) {
cachedHidRegistered = true;
LoadCachedHid();
}
return HDF_SUCCESS;
}
static int32_t HdfHIDDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
{
(void)cmd;
if (client == NULL || data == NULL || reply == NULL) {
HDF_LOGE("%s: param is null", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t HdfHIDDriverBind(struct HdfDeviceObject *device)
{
if (device == NULL) {
return HDF_ERR_INVALID_PARAM;
}
static struct IDeviceIoService hidService = {
.Dispatch = HdfHIDDispatch,
};
device->service = &hidService;
return HDF_SUCCESS;
}
struct HdfDriverEntry g_hdfHIDEntry = {
.moduleVersion = 1,
.moduleName = "HDF_HID",
.Bind = HdfHIDDriverBind,
.Init = HdfHIDDriverInit,
};
HDF_INIT(g_hdfHIDEntry);
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_HID_ADAPTER_H
#define HDF_HID_ADAPTER_H
typedef struct HidInformation {
uint32_t devType;
const char *devName;
} HidInfo;
enum HidType {
HID_TYPE_BEGIN_POS = 33, /* HID type start position */
HID_TYPE_MOUSE, /* Mouse */
HID_TYPE_KEYBOARD, /* Keyboard */
HID_TYPE_UNKNOWN, /* Unknown input device type */
};
void* HidRegisterHdfInputDev(HidInfo dev);
void HidUnregisterHdfInputDev(const void *inputDev);
void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value);
#endif
+105 -34
View File
@@ -16,22 +16,25 @@
#include "hdf_input_device_manager.h"
#define NODE_MODE 0660
#define SERVICE_NAME_LEN 16
#define SERVICE_NAME_LEN 24
#define INPUT_DEV_EXIST 1
#define INPUT_DEV_NOT_EXIST 0
#define MOUSE_DEV_ID 2
#define MAX_INPUT_DEV_NUM 32
#define INPUTDEV_FIRST_ID 1
#define FILLER_FLAG 1
#define PLACEHOLDER_LENGTH 2
#define PLACEHOLDER_LIMIT 10
InputManager *g_inputManager;
static InputManager *g_inputManager;
InputManager* GetInputManager(void)
{
return g_inputManager;
}
#ifndef __KERNEL__
int32_t TouchIoctl(InputDevice *inputdev, int32_t cmd, unsigned long arg);
uint32_t TouchPoll(struct file *filep, InputDevice *inputDev, poll_table *wait);
#endif
#ifndef __KERNEL__
static int32_t InputDevIoctl(struct file *filep, int32_t cmd, unsigned long arg)
{
int32_t ret;
@@ -106,7 +109,7 @@ static const struct file_operations_vfs inputDevOps = {
static bool IsHidDevice(uint32_t devType)
{
if (devType == INDEV_TYPE_MOUSE) {
if ((devType > INDEV_TYPE_HID_BEGIN_POS) && (devType < INDEV_TYPE_UNKNOWN)) {
return true;
}
return false;
@@ -117,7 +120,10 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev)
char svcName[SERVICE_NAME_LEN] = {0};
const char *moduleName = "HDF_HID";
struct HdfDeviceObject *hdfDev = NULL;
int32_t ret = snprintf_s(svcName, SERVICE_NAME_LEN, strlen("event") + 1, "%s%u", "event", MOUSE_DEV_ID);
int32_t len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH;
int32_t ret = snprintf_s(svcName, SERVICE_NAME_LEN, strlen("hdf_input_event") + len, "%s%u",
"hdf_input_event", inputDev->devId);
if (ret < 0) {
HDF_LOGE("%s: snprintf_s failed", __func__);
return NULL;
@@ -131,6 +137,33 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev)
return hdfDev;
}
static void HotPlugNotify(const InputDevice *inputDev, bool status)
{
struct HdfSBuf *sbuf = NULL;
HotPlugEvent event = {0};
int32_t ret;
sbuf = HdfSBufObtain(sizeof(HotPlugEvent));
if (sbuf == NULL) {
HDF_LOGE("%s: obtain buffer failed", __func__);
return;
}
event.devId = inputDev->devId;
event.devType = inputDev->devType;
event.status = status;
if (!HdfSbufWriteBuffer(sbuf, &event, sizeof(HotPlugEvent))) {
HDF_LOGE("%s: write buffer failed", __func__);
goto EXIT;
}
ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, sbuf);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: send event failed", __func__);
}
EXIT:
HdfSBufRecycle(sbuf);
}
static int32_t CreateDeviceNode(InputDevice *inputDev)
{
if (IsHidDevice(inputDev->devType)) {
@@ -139,13 +172,14 @@ static int32_t CreateDeviceNode(InputDevice *inputDev)
if (inputDev->hdfDevObj == NULL) {
return HDF_DEV_ERR_NO_DEVICE;
}
inputDev->devId = MOUSE_DEV_ID;
}
#ifndef __KERNEL__
char devNode[INPUT_DEV_PATH_LEN] = {0};
int32_t ret = snprintf_s(devNode, INPUT_DEV_PATH_LEN, strlen("/dev/input/event") + 1,
"%s%u", "/dev/input/event", inputDev->devId);
char *devNode = (char *)malloc(INPUT_DEV_PATH_LEN);
(void)memset_s(devNode, INPUT_DEV_PATH_LEN, 0, INPUT_DEV_PATH_LEN);
int32_t ret = snprintf_s(devNode, INPUT_DEV_PATH_LEN, strlen("/dev/input/hdf_input_event") + 1,
"%s%u", "/dev/input/hdf_input_event", inputDev->devId);
if (ret < 0) {
HDF_LOGE("%s: snprintf_s failed", __func__);
return HDF_FAILURE;
@@ -168,7 +202,10 @@ static void DeleteDeviceNode(InputDevice *inputDev)
if (IsHidDevice(inputDev->devType)) {
char svcName[SERVICE_NAME_LEN] = {0};
const char *moduleName = "HDF_HID";
int32_t ret = snprintf_s(svcName, SERVICE_NAME_LEN, strlen("event") + 1, "%s%u", "event", MOUSE_DEV_ID);
int32_t len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH;
int32_t ret = snprintf_s(svcName, SERVICE_NAME_LEN, strlen("hdf_input_event") + len, "%s%u",
"hdf_input_event", inputDev->devId);
if (ret < 0) {
HDF_LOGE("%s: snprintf_s failed", __func__);
return;
@@ -178,18 +215,12 @@ static void DeleteDeviceNode(InputDevice *inputDev)
}
#ifndef __KERNEL__
char devNode[INPUT_DEV_PATH_LEN] = {0};
int32_t ret = snprintf_s(devNode, INPUT_DEV_PATH_LEN, strlen("/dev/input/event") + 1, "%s%u",
"/dev/input/event", inputDev->devId);
if (ret < 0) {
HDF_LOGE("%s: snprintf_s failed", __func__);
return;
}
inputDev->devNode = devNode;
ret = unregister_driver(inputDev->devNode);
int32_t ret = unregister_driver(inputDev->devNode);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: delete dev node failed, ret %d", __func__, ret);
}
free((void *)inputDev->devNode);
inputDev->devNode = NULL;
#endif
HDF_LOGI("%s: delete node succ, devId is %d", __func__, inputDev->devId);
}
@@ -212,6 +243,7 @@ static void AddInputDevice(InputDevice *inputDev)
}
}
g_inputManager->devCount++;
HotPlugNotify(inputDev, ONLINE);
}
static int32_t CheckInputDevice(InputDevice *inputDev)
@@ -258,12 +290,14 @@ static int32_t DeleteInputDevice(InputDevice *inputDev)
EXIT:
g_inputManager->devCount--;
HotPlugNotify(inputDev, OFFLINE);
return HDF_SUCCESS;
}
#define DEFAULT_TOUCH_BUF_PKG_NUM 50
#define DEFAULT_KEY_BUF_PKG_NUM 10
#define DEFAULT_MOUSE_BUF_PKG_NUM 30
#define DEFAULT_KEYBOARD_BUF_PKG_NUM 20
#define DEFAULT_CROWN_BUF_PKG_NUM 20
#define DEFAULT_ENCODER_BUF_PKG_NUM 20
@@ -280,6 +314,9 @@ static int32_t AllocPackageBuffer(InputDevice *inputDev)
case INDEV_TYPE_MOUSE:
pkgNum = DEFAULT_MOUSE_BUF_PKG_NUM;
break;
case INDEV_TYPE_KEYBOARD:
pkgNum = DEFAULT_KEYBOARD_BUF_PKG_NUM;
break;
case INDEV_TYPE_CROWN:
pkgNum = DEFAULT_CROWN_BUF_PKG_NUM;
break;
@@ -313,14 +350,12 @@ static uint32_t AllocDeviceID(InputDevice *inputDev)
tmpDev = tmpDev->next;
}
for (id = INPUTDEV_FIRST_ID; id < MAX_INPUT_DEV_NUM + 1; id++) {
if (id == MOUSE_DEV_ID) {
continue;
}
if (idList[id] == 0) {
inputDev->devId = id;
return HDF_SUCCESS;
}
}
HDF_LOGE("%s: alloc device id failed", __func__);
return HDF_FAILURE;
}
@@ -334,7 +369,7 @@ int32_t RegisterInputDevice(InputDevice *inputDev)
return HDF_ERR_INVALID_PARAM;
}
if (g_inputManager == NULL || g_inputManager->initialized == false) {
if ((g_inputManager == NULL) || (g_inputManager->initialized == false)) {
HDF_LOGE("%s: dev manager is null or initialized failed", __func__);
return HDF_FAILURE;
}
@@ -366,18 +401,18 @@ EXIT:
return ret;
}
int32_t UnregisterInputDevice(InputDevice *inputDev)
void UnregisterInputDevice(InputDevice *inputDev)
{
int ret = HDF_FAILURE;
int32_t ret;
HDF_LOGI("%s: enter", __func__);
if (inputDev == NULL) {
HDF_LOGE("%s: inputdev is null", __func__);
return HDF_ERR_INVALID_PARAM;
return;
}
if (g_inputManager == NULL || g_inputManager->initialized == false) {
if ((g_inputManager == NULL) || (g_inputManager->initialized == false)) {
HDF_LOGE("%s: dev manager is null or initialized failed", __func__);
return HDF_FAILURE;
return;
}
OsalMutexLock(&g_inputManager->mutex);
@@ -393,14 +428,15 @@ int32_t UnregisterInputDevice(InputDevice *inputDev)
if (ret != HDF_SUCCESS) {
goto EXIT;
}
OsalMemFree(inputDev);
inputDev = NULL;
OsalMutexUnlock(&g_inputManager->mutex);
HDF_LOGI("%s: exit succ, devCount is %d", __func__, g_inputManager->devCount);
return HDF_SUCCESS;
return;
EXIT:
OsalMutexUnlock(&g_inputManager->mutex);
return ret;
return;
}
static uint32_t GetDeviceCount(void)
@@ -409,6 +445,40 @@ static uint32_t GetDeviceCount(void)
return g_inputManager->devCount;
}
static int32_t ScanAllDev(struct HdfSBuf *reply)
{
DevDesc sta;
InputDevice *tmpDev = g_inputManager->inputDevList;
while (tmpDev != NULL) {
sta.devType = tmpDev->devType;
sta.devId = tmpDev->devId;
if (!HdfSbufWriteBuffer(reply, &sta, sizeof(DevDesc))) {
HDF_LOGE("%s: HdfSbufWriteBuffer failed", __func__);
return HDF_FAILURE;
}
tmpDev = tmpDev->next;
}
HdfSbufWriteBuffer(reply, NULL, 0); // end flag
return HDF_SUCCESS;
}
static int32_t ScanDevice(struct HdfDeviceIoClient *client, int32_t cmd,
struct HdfSBuf *data, struct HdfSBuf *reply)
{
(void)cmd;
int32_t ret;
if ((client == NULL) || (data == NULL) || (reply == NULL)) {
HDF_LOGE("%s: param is null", __func__);
return HDF_FAILURE;
}
ret = ScanAllDev(reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: scan all dev failed", __func__);
}
return ret;
}
static int32_t HdfInputManagerBind(struct HdfDeviceObject *device)
{
if (device == NULL) {
@@ -418,6 +488,7 @@ static int32_t HdfInputManagerBind(struct HdfDeviceObject *device)
static IInputManagerService managerService = {
.getDeviceCount = GetDeviceCount,
.ioService.Dispatch = ScanDevice,
};
device->service = &managerService.ioService;
+25 -10
View File
@@ -19,7 +19,10 @@
#endif
#define HDF_LOG_TAG HDF_INPUT_DRV
#define INPUT_DEV_PATH_LEN 64
#define MAX_INPUT_DEV_NUM 32
#define DEV_NAME_LEN 16
#define ONLINE 0
#define OFFLINE 1
#define CHECK_RETURN_VALUE(ret) do { \
if ((ret) != HDF_SUCCESS) { \
@@ -27,6 +30,17 @@
} \
} while (0)
typedef struct {
uint32_t devId;
uint32_t devType;
} DevDesc;
typedef struct {
uint32_t devId;
uint32_t devType;
uint32_t status;
} HotPlugEvent;
typedef struct {
struct IDeviceIoService ioService;
uint32_t (*getDeviceCount)(void);
@@ -55,14 +69,15 @@ typedef struct {
} InputManager;
enum InputDevType {
INDEV_TYPE_TOUCH, /* Touchscreen */
INDEV_TYPE_KEY, /* Physical key */
INDEV_TYPE_KEYBOARD, /* Keyboard */
INDEV_TYPE_MOUSE, /* Mouse */
INDEV_TYPE_BUTTON, /* Virtual button */
INDEV_TYPE_CROWN, /* Watch crown */
INDEV_TYPE_ENCODER, /* Customized type of a specific function or event */
INDEV_TYPE_UNKNOWN, /* Unknown input device type */
INDEV_TYPE_TOUCH, /* Touchscreen */
INDEV_TYPE_KEY, /* Physical key */
INDEV_TYPE_BUTTON, /* Virtual button */
INDEV_TYPE_CROWN, /* Watch crown */
INDEV_TYPE_ENCODER, /* Customized type of a specific function or event */
INDEV_TYPE_HID_BEGIN_POS = 33, /* HID type start position */
INDEV_TYPE_MOUSE, /* Mouse */
INDEV_TYPE_KEYBOARD, /* Keyboard */
INDEV_TYPE_UNKNOWN, /* Unknown input device type */
};
enum InputIOsvcCmdId {
@@ -89,8 +104,8 @@ enum TouchIoctlCmd {
INPUT_IOCTL_RUN_CAPACITANCE_TEST,
INPUT_IOCTL_RUN_EXTRA_CMD,
};
InputManager* GetInputManager(void);
int32_t RegisterInputDevice(InputDevice *device);
int32_t UnregisterInputDevice(InputDevice *device);
void UnregisterInputDevice(InputDevice *device);
#endif
+12 -3
View File
@@ -14,8 +14,8 @@
#include "event_hub.h"
#include "hdf_key.h"
#define CHECK_PARSER_RET(ret, str) do { \
if (ret != HDF_SUCCESS) { \
#define CHECK_PARSER_RET(ret, str) do { \
if ((ret) != HDF_SUCCESS) { \
HDF_LOGE("%s: %s failed, ret = %d!", __func__, str, ret); \
return HDF_FAILURE; \
} \
@@ -40,7 +40,10 @@ static int32_t IoctlReadKeyEvent(KeyDriver *driver, unsigned long arg)
int32_t KeyIoctl(InputDevice *inputdev, int32_t cmd, unsigned long arg)
{
int32_t ret;
int32_t ret = HDF_FAILURE;
if (inputdev == NULL) {
return ret;
}
KeyDriver *driver = (KeyDriver *)inputdev->pvtData;
switch (cmd) {
case INPUT_IOCTL_GET_EVENT_DATA:
@@ -58,7 +61,13 @@ int32_t KeyIrqHandle(uint16_t intGpioNum, void *data)
{
uint16_t gpioValue;
KeyDriver *driver = (KeyDriver *)data;
if (driver == NULL) {
return HDF_FAILURE;
}
KeyEventData *event = &driver->eventData;
if (event == NULL) {
return HDF_FAILURE;
}
int32_t ret = GpioDisableIrq(intGpioNum);
if (ret != HDF_SUCCESS) {
+43 -23
View File
@@ -6,13 +6,13 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_touch.h"
#include "gpio_if.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "osal_io.h"
#include "event_hub.h"
#include "hdf_touch.h"
#define I2C_TYPE 0
#define SPI_TYPE 1
@@ -79,7 +79,10 @@ static int32_t IoctlGetChipName(TouchDriver *driver, unsigned long arg)
int32_t TouchIoctl(InputDevice *inputdev, int32_t cmd, unsigned long arg)
{
int32_t ret;
int32_t ret = HDF_FAILURE;
if (inputdev == NULL || inputdev->pvtData == NULL) {
return ret;
}
ChipDevice *device = (ChipDevice *)inputdev->pvtData;
TouchDriver *driver = device->driver;
switch (cmd) {
@@ -104,6 +107,9 @@ int32_t TouchIoctl(InputDevice *inputdev, int32_t cmd, unsigned long arg)
uint32_t TouchPoll(FAR struct file *filep, InputDevice *inputDev, poll_table *wait)
{
uint32_t pollMask = 0;
if (filep == NULL || filep->f_vnode == NULL) {
return pollMask;
}
InputDevice *inputdev = (InputDevice *)((struct drv_data*)filep->f_vnode->data)->priv;
if (inputdev == NULL) {
HDF_LOGE("%s: inputdev is null", __func__);
@@ -124,7 +130,7 @@ uint32_t TouchPoll(FAR struct file *filep, InputDevice *inputDev, poll_table *wa
static int32_t SetGpioDirAndLevel(int gpio, int dir, int level)
{
int32_t ret;
if (dir == GPIO_DIR_IN || dir == GPIO_DIR_OUT) {
if ((dir == GPIO_DIR_IN) || (dir == GPIO_DIR_OUT)) {
ret = GpioSetDir(gpio, dir);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: set gpio%d to %d dir failed, ret %d", __func__, gpio, dir, ret);
@@ -132,7 +138,7 @@ static int32_t SetGpioDirAndLevel(int gpio, int dir, int level)
}
}
if (level == GPIO_VAL_LOW || level == GPIO_VAL_HIGH) {
if ((level == GPIO_VAL_LOW) || (level == GPIO_VAL_HIGH)) {
ret = GpioWrite(gpio, level);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: pull gpio%d to %d level failed, ret %d", __func__, gpio, level, ret);
@@ -161,15 +167,20 @@ static int32_t SetGpio(uint16_t gpio, uint32_t dir, uint32_t status)
return HDF_SUCCESS;
}
int32_t HandlePowerEvent(ChipDevice *chipDev, uint32_t *timing)
static int32_t HandlePowerEvent(ChipDevice *chipDev, uint32_t *timing, uint32_t length)
{
int32_t ret = 0;
uint16_t gpio;
if (length <= PWR_DELAY_INDEX) {
HDF_LOGE("%s: invalid param", __func__);
return HDF_FAILURE;
}
uint32_t type = timing[PWR_TYPE_INDEX];
uint32_t status = timing[PWR_STATUS_INDEX];
uint32_t dir = timing[PWR_DIR_INDEX];
uint32_t delay = timing[PWR_DELAY_INDEX];
HDF_LOGD("%s: type = %d, status = %d, dir = %d, delay = %d", __func__, type, status, dir, delay);
HDF_LOGD("%s: type = %u, status = %u, dir = %u, delay = %u", __func__, type, status, dir, delay);
switch (type) {
case TYPE_VCC:
@@ -253,7 +264,7 @@ static int32_t SetPowerOnTiming(ChipDevice *chipDev)
}
for (i = 0; i < pwrOnTiming.count / PWR_CELL_LEN; i++) {
ret = HandlePowerEvent(chipDev, pwrOnTiming.buf);
ret = HandlePowerEvent(chipDev, pwrOnTiming.buf, PWR_CELL_LEN);
CHECK_RETURN_VALUE(ret);
pwrOnTiming.buf = pwrOnTiming.buf + PWR_CELL_LEN;
}
@@ -273,12 +284,13 @@ static void EventHandle(TouchDriver *driver, ChipDevice *chipDev)
}
}
int32_t IrqHandle(uint16_t intGpioNum, void *data)
static int32_t IrqHandle(uint16_t intGpioNum, void *data)
{
TouchDriver *driver = (TouchDriver *)data;
int ret = GpioDisableIrq(intGpioNum);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: disable irq failed, ret %d", __func__, ret);
return HDF_FAILURE;
}
EventHandle(driver, driver->device);
@@ -286,6 +298,7 @@ int32_t IrqHandle(uint16_t intGpioNum, void *data)
ret = GpioEnableIrq(intGpioNum);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: enable irq failed, ret %d", __func__, ret);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
@@ -302,6 +315,7 @@ static void InputFrameReport(TouchDriver *driver)
input_report_abs(dev, ABS_MT_POSITION_X, frame->fingers[i].x);
input_report_abs(dev, ABS_MT_POSITION_Y, frame->fingers[i].y);
input_report_abs(dev, ABS_MT_TRACKING_ID, frame->fingers[i].trackId);
input_mt_sync(dev);
}
}
@@ -320,8 +334,12 @@ static int32_t SetupChipIrq(ChipDevice *chipDev)
uint16_t intGpioNum = chipDev->boardCfg->pins.intGpio;
uint16_t irqFlag = chipDev->chipCfg->bus.chipI2c.irqFlag;
if (chipDev->driver == NULL) {
HDF_LOGE("%s: invalid param", __func__);
return HDF_FAILURE;
}
irqFlag |= GPIO_IRQ_USING_THREAD;
HDF_LOGD("%s: gpioNum = %d, irqFlag = %d", __func__, intGpioNum, irqFlag);
HDF_LOGD("%s: gpioNum = %u, irqFlag = %u", __func__, intGpioNum, irqFlag);
ret = GpioSetIrq(intGpioNum, irqFlag, IrqHandle, chipDev->driver);
if (ret != 0) {
HDF_LOGE("%s: register irq failed, ret %d", __func__, ret);
@@ -349,6 +367,10 @@ static int32_t ChipDriverInit(ChipDevice *chipDev)
CHECK_RETURN_VALUE(ret);
HDF_LOGI("%s: chipDetect succ, ret = %d ", __func__, ret);
ret = chipDev->ops->UpdateFirmware(chipDev);
CHECK_RETURN_VALUE(ret);
HDF_LOGI("%s: update firmware success", __func__);
ret = SetupChipIrq(chipDev);
CHECK_RETURN_VALUE(ret);
return HDF_SUCCESS;
@@ -377,12 +399,12 @@ static int32_t ChipMatchCheck(const ChipDevice *chipDev, const TouchDriver *driv
const struct DeviceResourceNode *boardNode = driver->boardCfg->boardNode;
const struct DeviceResourceNode *chipNode = chipDev->chipCfg->chipNode;
if (boardNode == NULL || boardNode->parent == NULL) {
if ((boardNode == NULL) || (boardNode->parent == NULL)) {
HDF_LOGE("%s: board node or upper node is null", __func__);
return HDF_FAILURE;
}
if (chipNode == NULL || chipNode->parent == NULL || chipNode->parent->parent == NULL) {
if ((chipNode == NULL) || (chipNode->parent == NULL) || (chipNode->parent->parent == NULL)) {
HDF_LOGE("%s: chip node or upper node is null ", __func__);
return HDF_FAILURE;
}
@@ -410,7 +432,7 @@ static int32_t DeviceBindDriver(ChipDevice *chipDev)
}
}
if (ret == HDF_FAILURE || driver == NULL) {
if ((ret == HDF_FAILURE) || (driver == NULL)) {
return HDF_FAILURE;
}
@@ -462,7 +484,7 @@ EXIT:
static int32_t TouchGetDevType(TouchDriver *driver, struct HdfSBuf *reply)
{
uint32_t devType = driver->devType;
HDF_LOGI("%s: enter, devType is %d", __func__, devType);
HDF_LOGI("%s: enter, devType is %u", __func__, devType);
bool ret = HdfSbufWriteUint32(reply, devType);
if (!ret) {
HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__);
@@ -480,7 +502,7 @@ static int32_t TouchSetPowerStatus(TouchDriver *driver, struct HdfSBuf *data)
return HDF_FAILURE;
}
driver->pwrStatus = pwrStatus;
HDF_LOGI("%s: set power status is %d", __func__, pwrStatus);
HDF_LOGI("%s: set power status is %u", __func__, pwrStatus);
return HDF_SUCCESS;
}
@@ -492,14 +514,14 @@ static int32_t TouchGetPowerStatus(TouchDriver *driver, struct HdfSBuf *reply)
HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s: get power status is %d", __func__, pwrStatus);
HDF_LOGI("%s: get power status is %u", __func__, pwrStatus);
return HDF_SUCCESS;
}
static int32_t TouchGetDeviceInfo(TouchDriver *driver, int32_t cmd, struct HdfSBuf *reply)
{
const char *info;
if (driver->device == NULL || driver->device->chipCfg == NULL) {
const char *info = NULL;
if ((driver->device == NULL) || (driver->device->chipCfg == NULL)) {
HDF_LOGE("%s: parameter invalid", __func__);
return HDF_ERR_INVALID_PARAM;
}
@@ -537,7 +559,7 @@ static int32_t TouchSetGestureMode(TouchDriver *driver, struct HdfSBuf *data)
return HDF_FAILURE;
}
driver->gestureMode = gestureMode;
HDF_LOGD("%s: set gesture mode is %d", __func__, gestureMode);
HDF_LOGD("%s: set gesture mode is %u", __func__, gestureMode);
return HDF_SUCCESS;
}
@@ -560,7 +582,7 @@ static int32_t TouchSelfCapacitance(TouchDriver *driver, struct HdfSBuf *data, s
HDF_LOGE("%s: HdfSbufWriteString failed", __func__);
return HDF_FAILURE;
}
HDF_LOGD("%s: capac test type is %d, test result is %s", __func__, capacTest.testType, capacTest.testResult);
HDF_LOGD("%s: capac test type is %u, test result is %s", __func__, capacTest.testType, capacTest.testResult);
return HDF_SUCCESS;
}
@@ -585,10 +607,9 @@ static int32_t TouchRunExtraCmd(TouchDriver *driver, struct HdfSBuf *data)
static int32_t HdfTouchDispatch(struct HdfDeviceIoClient *client, int32_t cmd,
struct HdfSBuf *data, struct HdfSBuf *reply)
{
(void)cmd;
int32_t ret;
TouchDriver *touchDriver = NULL;
if (client == NULL || client->device == NULL || data == NULL || reply == NULL) {
if ((client == NULL) || (client->device == NULL) || (data == NULL) || (reply == NULL)) {
HDF_LOGE("%s: param is null", __func__);
return HDF_FAILURE;
}
@@ -809,8 +830,7 @@ static void HdfTouchDriverRelease(struct HdfDeviceObject *device)
}
if (inputDev != NULL) {
(void)UnregisterInputDevice(inputDev);
OsalMemFree(inputDev);
UnregisterInputDevice(inputDev);
driver->inputDev = NULL;
}
+1
View File
@@ -96,6 +96,7 @@ struct TouchChipOps {
int32_t (*Resume)(ChipDevice *device);
int32_t (*Suspend)(ChipDevice *device);
int32_t (*DataHandle)(ChipDevice *device);
int32_t (*UpdateFirmware)(ChipDevice *device);
};
typedef struct {
+5 -3
View File
@@ -20,6 +20,8 @@
#define DEFAULT_I2C_SPEED 400
#define DEFAULT_SPI_SPEED 10000
#define I2C 0
#define SPI 1
int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyChipCfg *config)
{
@@ -71,7 +73,7 @@ static int32_t ParseBus(struct DeviceResourceIface *parser, const struct DeviceR
ret = parser->GetUint8(busNode, "busType", &bus->busType, 0);
CHECK_PARSER_RET(ret, "GetUint8");
if (bus->busType == 0) {
if (bus->busType == I2C) {
ret = parser->GetUint8(busNode, "busNum", &bus->i2c.busNum, 0);
CHECK_PARSER_RET(ret, "GetUint8");
ret = parser->GetUint16(busNode, "clkGpio", &bus->i2c.clkGpio, 0);
@@ -82,7 +84,7 @@ static int32_t ParseBus(struct DeviceResourceIface *parser, const struct DeviceR
CHECK_PARSER_RET(ret, "GetUint32Array");
ret = parser->GetUint32Array(busNode, "i2cDataIomux", bus->i2c.i2cDataReg, REG_CONFIG_LEN, 0);
CHECK_PARSER_RET(ret, "GetUint32Array");
} else if (bus->busType == 1) {
} else if (bus->busType == SPI) {
ret = parser->GetUint8(busNode, "busNum", &bus->spi.busNum, 0);
CHECK_PARSER_RET(ret, "GetUint8");
ret = parser->GetUint16(busNode, "clkGpio", &bus->spi.clkGpio, 0);
@@ -274,7 +276,7 @@ int32_t ParseTouchChipConfig(const struct DeviceResourceNode *node, TouchChipCfg
CHECK_PARSER_RET(ret, "GetUint16");
ret = parser->GetUint8(node, "busType", &config->bus.busType, 0);
CHECK_PARSER_RET(ret, "GetUint8");
if (config->bus.busType == 0) {
if (config->bus.busType == I2C) {
ret = parser->GetUint16(node, "irqFlag", &config->bus.chipI2c.irqFlag, 0);
CHECK_PARSER_RET(ret, "GetUint16");
ret = parser->GetUint32(node, "deviceAddr", &config->bus.chipI2c.commAddr, 0);
@@ -41,7 +41,7 @@ static int32_t ChipDetect(ChipDevice *device)
CHIP_CHECK_RETURN(ret);
ret = InputI2cRead(i2cClient, &regAddr, 1, &regValue, 1);
CHIP_CHECK_RETURN(ret);
HDF_LOGI("%s: Report rate is %d * 10", __func__, regValue);
HDF_LOGI("%s: Report rate is %u * 10", __func__, regValue);
regAddr = FTS_REG_FW_VER;
ret = InputI2cWrite(i2cClient, &regAddr, 1);
@@ -55,7 +55,7 @@ static int32_t ChipDetect(ChipDevice *device)
CHIP_CHECK_RETURN(ret);
ret = InputI2cRead(i2cClient, &regAddr, 1, &regValue, 1);
CHIP_CHECK_RETURN(ret);
HDF_LOGI("%s: Chip ID is %d", __func__, regValue);
HDF_LOGI("%s: Chip ID is %u", __func__, regValue);
(void)ChipInit(device);
(void)ChipResume(device);
+21 -1
View File
@@ -80,6 +80,8 @@ static int ChipCleanBuffer(InputI2cClient *i2cClient)
return ret;
}
#define X_OFFSET 1
static void ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, uint8_t pointNum)
{
int32_t chipVer = device->chipCfg->chipVersion;
@@ -89,10 +91,15 @@ static void ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, u
for (i = 0; i < pointNum; i++) {
if (chipVer == 0) { // chipversion A:gt911_zsj5p5
frame->fingers[i].trackId = buf[GT_POINT_SIZE * i + GT_TRACK_ID];
frame->fingers[i].y = (buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) |
((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET);
frame->fingers[i].x = (buf[GT_POINT_SIZE * i + GT_Y_LOW] & ONE_BYTE_MASK) |
((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET);
if (frame->fingers[i].x == 0) {
frame->fingers[i].x = X_OFFSET;
}
HDF_LOGD("%s: x = %d, y = %d", __func__, frame->fingers[i].x, frame->fingers[i].y);
} else if (chipVer == 1) { // chipversion B:gt911_zsj4p0
frame->fingers[i].x = resX - 1 - ((buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) |
((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET));
@@ -137,7 +144,7 @@ static int32_t ChipDataHandle(ChipDevice *device)
reg[1] = GT_X_LOW_BYTE_BASE & ONE_BYTE_MASK;
pointNum = touchStatus & GT_FINGER_NUM_MASK;
if (pointNum == 0 || pointNum > MAX_SUPPORT_POINT) {
HDF_LOGE("%s: pointNum is invalid, %d", __func__, pointNum);
HDF_LOGE("%s: pointNum is invalid, %u", __func__, pointNum);
(void)ChipCleanBuffer(i2cClient);
OsalMutexUnlock(&device->driver->mutex);
return HDF_FAILURE;
@@ -155,12 +162,25 @@ EXIT:
return HDF_SUCCESS;
}
static int32_t UpdateFirmware(ChipDevice *device)
{
int32_t ret;
InputI2cClient *i2cClient = &device->driver->i2cClient;
ret = InputI2cWrite(i2cClient, firmWareParm, FIRMWARE_LEN);
if (ret < 0) {
return HDF_FAILURE;
}
HDF_LOGI("%s: update firmware success\n", __func__);
return HDF_SUCCESS;
}
static struct TouchChipOps g_gt911ChipOps = {
.Init = ChipInit,
.Detect = ChipDetect,
.Resume = ChipResume,
.Suspend = ChipSuspend,
.DataHandle = ChipDataHandle,
.UpdateFirmware = UpdateFirmware,
};
static TouchChipCfg *ChipConfigInstance(struct HdfDeviceObject *device)
+25 -6
View File
@@ -10,20 +10,21 @@
#define TOUCH_GT911_H
/* the macro defines of GT911 */
#define MAX_SUPPORT_POINT 10
#define MAX_SUPPORT_POINT 5
#define ONE_BYTE_MASK 0xFF
#define ONE_BYTE_OFFSET 8
#define GT_EVENT_UP 0x80
#define GT_EVENT_INVALID 0
#define GT_POINT_SIZE 8
#define GT_X_LOW 0
#define GT_X_HIGH 1
#define GT_Y_LOW 2
#define GT_Y_HIGH 3
#define GT_TRACK_ID 0
#define GT_X_LOW 1
#define GT_X_HIGH 2
#define GT_Y_LOW 3
#define GT_Y_HIGH 4
#define GT_ADDR_LEN 2
#define GT_BUF_STATE_ADDR 0x814E
#define GT_X_LOW_BYTE_BASE 0x8150
#define GT_X_LOW_BYTE_BASE 0x814F
#define GT_FINGER_NUM_MASK 0x0F
#define GT_CLEAN_DATA_LEN 3
#define GT_REG_HIGH_POS 0
@@ -43,5 +44,23 @@
#define GT_SOLU_X_HIGH 7
#define GT_SOLU_Y_LOW 8
#define GT_SOLU_Y_HIGH 9
#define FIRMWARE_LEN 188
uint8_t firmWareParm[FIRMWARE_LEN] = {
0x80, 0x47, 0x45, 0xC0, 0x03, 0xE0, 0x01, 0x05, 0x3D, 0x00, 0x01, 0x08, 0x28, 0x0F,
0x50, 0x32, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1A, 0x1E,
0x14, 0x86, 0x26, 0x08, 0x55, 0x57, 0xB2, 0x04, 0x00, 0x00, 0x00, 0x42, 0x02, 0x11,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x78, 0x94,
0xD5, 0x02, 0x07, 0x00, 0x00, 0x04, 0x97, 0x40, 0x00, 0x8A, 0x4A, 0x00, 0x80, 0x55,
0x00, 0x77, 0x61, 0x00, 0x6F, 0x70, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x0E, 0x0C, 0x0A, 0x08, 0x06, 0x04, 0x02, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x22, 0x21, 0x20, 0x1F, 0x1E, 0x1D, 0x00, 0x02, 0x04, 0x06,
0x08, 0x0A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5C, 0x01
};
#endif
+11 -12
View File
@@ -17,12 +17,12 @@
static struct NetDeviceImpl *g_netDeviceImplTable[MAX_NETDEVICE_COUNT] = {NULL};
static bool FindAvailableTable(int32_t *index)
static bool FindAvailableTable(uint32_t *index)
{
int32_t i;
uint32_t i;
if (index == NULL) {
HDF_LOGE("Find Available table index error!");
HDF_LOGE("%s Find Available table index error!", __func__);
return false;
}
for (i = 0; i < MAX_NETDEVICE_COUNT; i++) {
@@ -34,7 +34,7 @@ static bool FindAvailableTable(int32_t *index)
return false;
}
static bool AddNetDeviceImplToTable(int32_t index, struct NetDeviceImpl *netDeviceImpl)
static bool AddNetDeviceImplToTable(uint32_t index, struct NetDeviceImpl *netDeviceImpl)
{
if (index >= MAX_NETDEVICE_COUNT) {
HDF_LOGE("%s error because of not enough space!", __func__);
@@ -68,7 +68,6 @@ static struct NetDeviceImpl *InitNetDeviceImpl(NetDevice *nd, NetIfCategory ifCa
HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
return NULL;
}
(void)memset_s(ndImpl, sizeof(struct NetDeviceImpl), 0, sizeof(struct NetDeviceImpl));
ndImpl->netDevice = nd;
if (RegisterNetDeviceImpl(ndImpl) != HDF_SUCCESS) {
@@ -100,6 +99,7 @@ static void DeInitNetDeviceImpl(struct NetDeviceImpl *netDeviceImpl)
/* last release netDeviceImpl */
OsalMemFree(netDeviceImpl);
netDeviceImpl = NULL;
HDF_LOGI("%s success!", __func__);
return;
}
@@ -117,7 +117,7 @@ static struct NetDeviceImpl *GetImplByNetDevice(const struct NetDevice *netDevic
}
}
}
HDF_LOGE("Don't Get Impl by netdevice");
HDF_LOGE("%s Get Impl by netdevice failed", __func__);
return ndImpl;
}
@@ -125,7 +125,7 @@ struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory
{
NetDevice *netDevice = NULL;
struct NetDeviceImpl *ndImpl = NULL;
int32_t index = 0;
uint32_t index = 0;
int32_t ret;
if ((ifName == NULL) || (strlen(ifName) != len) || (strlen(ifName) > IFNAMSIZ - 1)) {
@@ -137,9 +137,8 @@ struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory
HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
return NULL;
}
(void)memset_s(netDevice, sizeof(NetDevice), 0, sizeof(NetDevice));
if (memcpy_s(netDevice->name, IFNAMSIZ, ifName, len + 1) != EOK) {
HDF_LOGE("%s fail: memcpy_s fail!", __func__);
if (strcpy_s(netDevice->name, IFNAMSIZ, ifName) != EOK) {
HDF_LOGE("%s fail: strcpy_s fail!", __func__);
OsalMemFree(netDevice);
return NULL;
}
@@ -318,7 +317,7 @@ static int32_t NetIfRxImpl(const struct NetDevice *netDevice, NetBuf *buff, Rece
ProcessingResult ret = PROCESSING_CONTINUE;
if (ndImpl == NULL || ndImpl->interFace == NULL || ndImpl->interFace->receive == NULL) {
HDF_LOGE("NetIfRxImpl fail : netdevice not exist!");
HDF_LOGE("%s: NetIfRxImpl fail : netdevice not exist!", __func__);
return HDF_ERR_INVALID_PARAM;
}
@@ -333,7 +332,7 @@ static int32_t NetIfRxImpl(const struct NetDevice *netDevice, NetBuf *buff, Rece
HDF_LOGI("NetIfRxImpl specialEtherType Process not need TCP/IP stack!");
return HDF_SUCCESS;
} else {
HDF_LOGE("NetIfRxImpl specialEtherType Process error");
HDF_LOGE("%s: NetIfRxImpl specialEtherType Process error", __func__);
return HDF_FAILURE;
}
}
@@ -75,7 +75,7 @@ static int32_t GetEapol(const struct NetDevice *netDevice, struct EapolRx *buff)
p = NetBufGetAddress(netBuff, E_DATA_BUF);
len = NetBufGetDataLen(netBuff);
if (len > eapolRx->len) {
HDF_LOGE("%s fail : eapolRx->len too small! netBuff->len(%d) > eapolRx->len(%d).",
HDF_LOGE("%s fail : eapolRx->len too small! netBuff->len(%u) > eapolRx->len(%u).",
__func__, netBuff->len, eapolRx->len);
NetBufFree(netBuff);
return HDF_FAILURE;
@@ -158,7 +158,7 @@ static void HandleEapolQueue(struct EapolData *eapol)
HDF_LOGE("%s discard pre netbuf : intervalTime(%lld) > EAPOL_MAX_ENQUEUE_TIME.", __func__,
intervalTime);
} else {
HDF_LOGE("%s discard pre netbuf : eapol->count(%d) = maxCount(%d).", __func__, eapol->count, maxCount);
HDF_LOGE("%s discard pre netbuf : eapol->count(%u) = maxCount(%u).", __func__, eapol->count, maxCount);
}
eapol->count--;
eapol->enqueueTime = currentTime;
@@ -16,7 +16,7 @@
#define EAPOL_MAX_ENQUEUE_TIME 300 /* 300 Second */
struct EapolData {
bool regFlag; /* is already regstered */
bool regFlag; /* is already registered */
uint16_t count; /* eapol frame count in NetBuffQueue. */
uint16_t maxCount;
int64_t enqueueTime; /* record eapol frame time for dfx. */

Some files were not shown because too many files have changed in this diff Show More