mirror of
https://github.com/openharmony/vendor_beken.git
synced 2026-07-01 21:44:29 -04:00
add beken vendor
Signed-off-by: wanqing.lin <wanqing.lin@bekencorp.com>
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
# vendor_beken
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
vendor_beken
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
@@ -33,4 +33,4 @@ Software architecture description
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
@@ -1,25 +1,27 @@
|
||||
# vendor_beken
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
vendor_beken平台基于beken 7235芯片, 集wifi/ble功能于一体
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
app ==> func ==> driver
|
||||
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
1. 在本地创建一个用于存放源码的目录,进入该目录
|
||||
2. 输入以下命令初始化代码仓库 :
|
||||
repo init -u https://gitee.com/openharmony-sig/manifest.git -b master --no-repo-verify -m devboard_beken.xml
|
||||
3. 输入repo sync -c下载所有代码到本地
|
||||
4. 输入hb set, 选择beken下的wifi_bk7235产品
|
||||
6. 编译结果为out/bk7235x/wifi_bk7235/bk7235_sdk_ota.bin
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
1. 使用tools/目录下的bk_writer工具, bk7235_sdk_ota.bin下载到bk7235开发板中
|
||||
2. 给bk7235开发板重新上电, 系统启动后进行命令行
|
||||
3. 在命令行中输入help查看可用命令
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
@@ -29,11 +31,3 @@ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
group("test_xts_part1") {
|
||||
deps = [
|
||||
|
||||
"//test/xts/tools/lite/hctest:hctest",
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"product_name": "xts_test_part1",
|
||||
"ohos_version": "OpenHarmony 3.0",
|
||||
"type": "mini",
|
||||
"version": "3.0",
|
||||
"device_company": "beken",
|
||||
"board": "bk7235x",
|
||||
"kernel_type": "liteos_m",
|
||||
"kernel_version": "3.0",
|
||||
"subsystems": [
|
||||
{
|
||||
"subsystem": "kernel",
|
||||
"components": [
|
||||
{
|
||||
"component": "liteos_m",
|
||||
"features": [
|
||||
"ohos_kernel_liteos_m_lwip_path = \"//device/soc/beken/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2\""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "hiviewdfx",
|
||||
"components": [
|
||||
{ "component": "hilog_lite", "features":[] },
|
||||
{ "component": "hievent_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "systemabilitymgr",
|
||||
"components": [
|
||||
{ "component": "samgr_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "communication",
|
||||
"components": [
|
||||
{ "component": "wifi_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "commonlibrary",
|
||||
"components": [
|
||||
{ "component": "file", "features":[] },
|
||||
{ "component": "timer_task", "features":[] },
|
||||
{ "component": "kal_timer", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "startup",
|
||||
"components": [
|
||||
{ "component": "bootstrap_lite", "features":[] },
|
||||
{ "component": "init_lite", "features":["enable_ohos_startup_init_feature_begetctl_liteos = false"] },
|
||||
{ "component": "syspara_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "security",
|
||||
"components": [
|
||||
{ "component": "huks", "features":
|
||||
[
|
||||
"disable_huks_binary = true",
|
||||
"disable_authenticate = true",
|
||||
"huks_use_lite_storage = true",
|
||||
"huks_use_hardware_root_key = true",
|
||||
"huks_config_file = \"hks_config_lite.h\"",
|
||||
"ohos_security_huks_mbedtls_porting_path = \"//device/soc/beken/bk7235/liteos_m/components/mbedtls\""
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "iothardware",
|
||||
"components": [
|
||||
{ "component": "peripheral", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "xts",
|
||||
"components": [
|
||||
{"component": "xts_acts", "features":
|
||||
[
|
||||
"enable_ohos_test_xts_acts_use_thirdparty_lwip = true",
|
||||
"build_xts = true"
|
||||
]
|
||||
},
|
||||
{ "component": "xts_tools", "features":[] }
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
"third_party_dir": "//third_party",
|
||||
"product_adapter_dir": "//vendor/beken/test_xts_part1/hals",
|
||||
"xts_list": [
|
||||
{
|
||||
"enable": "true",
|
||||
"xts_modules": [
|
||||
"ActsKvStoreTest",
|
||||
"ActsDfxFuncTest",
|
||||
"ActsHieventLiteTest",
|
||||
"ActsSamgrTest",
|
||||
"ActsParameterTest",
|
||||
"ActsWifiServiceTest",
|
||||
"ActsWifiIotTest",
|
||||
"ActsBootstrapTest"
|
||||
]
|
||||
}
|
||||
],
|
||||
"tests_list": [
|
||||
{
|
||||
"enable": "false"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
harmonyos_connect_package_path = "//vendor/huawei/harmonyos_connect"
|
||||
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
ohos_type = "mini"
|
||||
} else if (ohos_kernel_type == "liteos_a") {
|
||||
ohos_type = "small"
|
||||
} else if (ohos_kernel_type == "linux") {
|
||||
ohos_type = "standard"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//applications/iot_solution/device.gni")
|
||||
|
||||
static_library("ota_update_adapter") {
|
||||
sources = [
|
||||
"src/hilink_open_ota_adapter.c",
|
||||
"src/hilink_open_ota_mcu_adapter.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
# "//device/asr/asr582x/drivers/ota"
|
||||
]
|
||||
|
||||
deps = [ "$ohos_vendor_adapter_dir/hals/update:hal_update_static" ]
|
||||
}
|
||||
Executable
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2021. All rights reserved.
|
||||
* Description: OTA适配层接口(需设备厂商实现)
|
||||
*/
|
||||
#ifndef HILINK_OPEN_OTA_ADAPTER_H
|
||||
#define HILINK_OPEN_OTA_ADAPTER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* OTA升级分区1 */
|
||||
#ifndef UPGRADE_FW_BIN1
|
||||
#define UPGRADE_FW_BIN1 0x00
|
||||
#endif
|
||||
|
||||
/* OTA升级分区2 */
|
||||
#ifndef UPGRADE_FW_BIN2
|
||||
#define UPGRADE_FW_BIN2 0x01
|
||||
#endif
|
||||
|
||||
/* 只有MCU升级时立即重启 */
|
||||
#ifndef RESTART_FLAG_NOW
|
||||
#define RESTART_FLAG_NOW 0x01
|
||||
#endif
|
||||
|
||||
/* 有模组时切换分区后再重启 */
|
||||
#ifndef RESTART_FLAG_LATER
|
||||
#define RESTART_FLAG_LATER 0x02
|
||||
#endif
|
||||
|
||||
/* 模组可以重启 */
|
||||
#ifndef MODULE_CAN_REBOOT
|
||||
#define MODULE_CAN_REBOOT 0x01
|
||||
#endif
|
||||
|
||||
/* 模组不能重启 */
|
||||
#ifndef MODULE_CANNOT_REBOOT
|
||||
#define MODULE_CANNOT_REBOOT 0x00
|
||||
#endif
|
||||
|
||||
/* 手动升级 */
|
||||
#ifndef UPDATE_TYPE_MANUAL
|
||||
#define UPDATE_TYPE_MANUAL 0x00
|
||||
#endif
|
||||
|
||||
/* 自动升级 */
|
||||
#ifndef UPDATE_TYPE_AUTO
|
||||
#define UPDATE_TYPE_AUTO 0x01
|
||||
#endif
|
||||
|
||||
/* 返回正常 */
|
||||
#ifndef RETURN_OK
|
||||
#define RETURN_OK 0
|
||||
#endif
|
||||
/* 没有MCU */
|
||||
#ifndef RETURN_ERROR_NO_MCU
|
||||
#define RETURN_ERROR_NO_MCU (-1)
|
||||
#endif
|
||||
/* 返回其他错误 */
|
||||
#ifndef RETURN_ERROR
|
||||
#define RETURN_ERROR (-2)
|
||||
#endif
|
||||
/* MCU不需要升级 */
|
||||
#ifndef RETURN_MCU_NO_NEED_OTA
|
||||
#define RETURN_MCU_NO_NEED_OTA (-3)
|
||||
#endif
|
||||
|
||||
typedef void (*GetOtaVerCb)(const char *version);
|
||||
typedef void (*TrigSelfUpdateCb)(const char *url, const unsigned int size);
|
||||
|
||||
/*
|
||||
* Flash初始化
|
||||
* 返回值是true时,表示初始化正常
|
||||
* 返回值是false时,表示初始化异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashInit(void);
|
||||
|
||||
/*
|
||||
* 判断需要升级的分区
|
||||
* 返回值是UPGRADE_FW_BIN1时,表示升级固件到分区1
|
||||
* 返回值是UPGRADE_FW_BIN2时,表示升级固件到分区2
|
||||
*/
|
||||
unsigned int HILINK_OtaAdapterGetUpdateIndex(void);
|
||||
|
||||
/*
|
||||
* 擦除需要升级的分区
|
||||
* size表示需要擦除的分区大小
|
||||
* 返回值是0时,表示擦除成功
|
||||
* 返回值是-1时,表示擦除失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashErase(unsigned int size);
|
||||
|
||||
/*
|
||||
* 升级数据写入升级的分区
|
||||
* buf表示待写入数据
|
||||
* bufLen表示待写入数据的长度
|
||||
* 返回值是0时,表示写入成功
|
||||
* 返回值是-1时,表示写入失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int bufLen);
|
||||
|
||||
/*
|
||||
* 读取升级分区数据
|
||||
* offset表示读写偏移
|
||||
* buf表示输出数据的内存地址
|
||||
* bufLen表示输出数据的内存长度
|
||||
* 返回值是0时,表示读取成功
|
||||
* 返回值是-1时,表示读取失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int bufLen);
|
||||
|
||||
/*
|
||||
* 分区升级结束
|
||||
* 返回值是true时,表示结束正常
|
||||
* 返回值是false时,表示结束异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashFinish(void);
|
||||
|
||||
/* 获取升级区间最大长度 */
|
||||
unsigned int HILINK_OtaAdapterFlashMaxSize(void);
|
||||
|
||||
/*
|
||||
* 根据标志重启模组
|
||||
* flag表示重启标志
|
||||
* 当flag是RESTART_FLAG_NOW时,表示只有MCU升级时立即重启
|
||||
* 当flag是RESTART_FLAG_LATER时,表示有模组时切换分区后再重启
|
||||
*/
|
||||
void HILINK_OtaAdapterRestart(int flag);
|
||||
|
||||
/*
|
||||
* 开始模组升级
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将开始启动升级流程
|
||||
* 返回值是RETURN_ERROR时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:在手动场景场景下,HiLink SDK在接收到用户发出的升级指令后,将直接调用此接口;
|
||||
* 在自动升级场景下,当HiLink SDK在调用HilinkGetRebootFlag接口返回值是MODULE_CAN_REBOOT时,HiLink SDK将调用此接口。
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_OtaStartProcess(int type);
|
||||
|
||||
/*
|
||||
* 模组升级结束
|
||||
* status表示升级结果
|
||||
* 当status是100时,表示升级成功
|
||||
* 当status不是100时,表示升级失败
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将置升级标志或切换运行区标志
|
||||
* 返回值不是RETURN_OK时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:HiLink SDK在将固件写入到OTA升级区后,且完整性校验通过后,将调用厂商适配的此接口;
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等;升级类型是否为自动升级可参考接口HilinkOtaStartProcess的参数type的描述。
|
||||
*/
|
||||
int HILINK_OtaEndProcess(int status);
|
||||
|
||||
/*
|
||||
* 判断模组是否能立即升级并重启
|
||||
* 返回值是MODULE_CAN_REBOOT时,表示模组可以立即升级并重启,HiLink SDK将开始自动升级流程。
|
||||
* 返回值是MODULE_CANNOT_REBOOT时,表示模组不能立即升级并重启,HiLink SDK将不进行本次自动升级流程。
|
||||
* 注意:在用户同意设备可以自动升级的情况下,HiLink SDK调用此接口获取设备当前业务状态下,模组是否可以立即升级并重启的标志。
|
||||
* 只有当设备处于业务空闲状态时,接口才可以返回MODULE_CAN_REBOOT。
|
||||
* 当设备处于业务非空闲状态时,接口返回MODULE_CANNOT_REBOOT。
|
||||
*/
|
||||
int HILINK_GetRebootFlag(void);
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本检测
|
||||
* 检测到的版本,sdk将通过cb回调函数上报。如果不需要获取版本号,则可将cb置空。
|
||||
* 上报的version如果为空,则未成功获取到新版本。
|
||||
* 注意:1、建议调用频次最多一天一次
|
||||
* 2、首次通过手机配网成功后不能调用,建议连云成功后至少5s后调用
|
||||
*/
|
||||
void HILINK_TrigOtaVersionCheck(GetOtaVerCb cb);
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本升级
|
||||
* 检测到的版本,sdk将通过cb回调函数触发升级
|
||||
*/
|
||||
void HILINK_TrigOtaSelfUpdate(TrigSelfUpdateCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
|
||||
* Description: MCU OTA适配层接口(需设备厂商实现)
|
||||
*/
|
||||
#ifndef HILINK_OPEN_OTA_MCU_ADAPTER_H
|
||||
#define HILINK_OPEN_OTA_MCU_ADAPTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 返回正常 */
|
||||
#ifndef RETURN_OK
|
||||
#define RETURN_OK 0
|
||||
#endif
|
||||
|
||||
/* 没有MCU */
|
||||
#ifndef RETURN_ERROR_NO_MCU
|
||||
#define RETURN_ERROR_NO_MCU (-1)
|
||||
#endif
|
||||
|
||||
/* MCU返回其他错误 */
|
||||
#ifndef RETURN_ERROR
|
||||
#define RETURN_ERROR (-2)
|
||||
#endif
|
||||
|
||||
/* MCU不需要升级 */
|
||||
#ifndef RETURN_MCU_NO_NEED_OTA
|
||||
#define RETURN_MCU_NO_NEED_OTA (-3)
|
||||
#endif
|
||||
|
||||
/* 手动升级 */
|
||||
#ifndef UPDATE_TYPE_MANUAL
|
||||
#define UPDATE_TYPE_MANUAL 0x00
|
||||
#endif
|
||||
|
||||
/* 自动升级 */
|
||||
#ifndef UPDATE_TYPE_AUTO
|
||||
#define UPDATE_TYPE_AUTO 0x01
|
||||
#endif
|
||||
|
||||
/* 开始发送MCU数据 */
|
||||
#ifndef START_SEND_DATA
|
||||
#define START_SEND_DATA 0
|
||||
#endif
|
||||
|
||||
/* 发送MCU数据结束 */
|
||||
#ifndef STOP_SEND_DATA
|
||||
#define STOP_SEND_DATA 1
|
||||
#endif
|
||||
|
||||
/* 异常终止 */
|
||||
#ifndef SEND_DATA_ERROR
|
||||
#define SEND_DATA_ERROR 2
|
||||
#endif
|
||||
|
||||
typedef int (*RptUpgProgressFlagCb)(void);
|
||||
|
||||
/*
|
||||
* 获取MCU当前版本
|
||||
* version表示版本字符串
|
||||
* inLen表示输入字符串长度
|
||||
* outLen表示输出字符串长度
|
||||
* 返回值是RETURN_OK时,表示获取成功
|
||||
* 返回值是RETURN_ERROR_NO_MCU时,表示没有MCU
|
||||
* 返回值是RETURN_ERROR时,表示获取失败
|
||||
* 注意:如果获取不到MCU的版本,则不对MCU进行升级。
|
||||
* 建议厂商在MCU正常启动后,或升级启动后,就将MCU的版本号传递给模组,确保模组可以获取到MCU的版本。
|
||||
*/
|
||||
int HILINK_GetMcuVersion(char *version, unsigned int inLen, unsigned int *outLen);
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知MCU固件传输的状态
|
||||
* flag表示升级流程标志
|
||||
* 当flag是START_SEND_DATA时,表示通知模组即将开始发送MCU固件数据包
|
||||
* 当flag是STOP_SEND_DATA时,表示通知模组完整的MCU固件包已发送完成
|
||||
* 当flag是SEND_DATA_ERROR时,表示通知模组本次MCU固件升级异常终止
|
||||
* len表示MCU固件包的大小
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,表示处理失败,HiLink SDK将终止本次MCU升级流程
|
||||
* 注意:当flag是STOP_SEND_DATA时,此接口需返回MCU侧固件升级的结果;当flag是其它值时,需返回接口接收到此消息后的处理结果。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_NotifyOtaStatus(int flag, unsigned int len, unsigned int type);
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知厂商发送MCU固件文件数据
|
||||
* data表示发送的数据
|
||||
* len表示发送的数据的长度
|
||||
* offset表示发送的数据起始位置相对于完整固件包的偏移量
|
||||
* 此接口需要返回MCU接收这部分数据的处理结果
|
||||
* 返回值是RETURN_OK时,模组将通知的数据正确发送给MCU,且MCU正确处理发送的数据,HiLink SDK将继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,模组或MCU未能正常处理通知的MCU的固件文件数据,HiLink SDK将终止本次MCU固件升级流程
|
||||
*/
|
||||
int HILINK_NotifyOtaData(const unsigned char *data, unsigned int len, unsigned int offset);
|
||||
|
||||
/*
|
||||
* 产品OTA升级时下载升级包进度为100%后会重启, APP上显示设备重启中
|
||||
* 然后等设备起来后上报进度0, APP上才会显示升级成功
|
||||
* 通过回调函数cb来设置Hilink Sdk被拉起后是否立即向APP上报进度0
|
||||
* cb返回1时hilink sdk被拉起后不会立即上报进度0,
|
||||
* 上报时机由产品自己决定,调用hilink_ota_rpt_prg进行上报
|
||||
* cb返回0时hilink sdk被拉起后会立即上报进度0
|
||||
* 产品根据自身升级情况判断是否需要注册cb,如不注册则默认hilink sdk被拉起后会立即上报进度0
|
||||
*/
|
||||
void HILINK_PowerOnRptUpgProgress(RptUpgProgressFlagCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* HILINK_OPEN_OTA_BRIDGE_ADAPTER_H */
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
|
||||
* Description: OTA适配实现 (需设备厂商实现)
|
||||
*/
|
||||
#include "hilink_open_ota_adapter.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#define DOWNLOAD_PATITION_ADDR 0x253000 //68+2048+300KB
|
||||
#define DOWNLOAD_PATITION_LEN 0x187000 //1536KB
|
||||
static unsigned int write_length = 0;
|
||||
#define HILINK_OK 0
|
||||
#define HILINK_ERROR -1
|
||||
|
||||
/*
|
||||
* Flash初始化
|
||||
* 返回值是true时,表示初始化正常
|
||||
* 返回值是false时,表示初始化异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashInit(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashInit start\r\n");
|
||||
IoTFlashInit();
|
||||
write_length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 判断需要升级的分区
|
||||
* 返回值是UPGRADE_FW_BIN1时,表示升级固件到分区1
|
||||
* 返回值是UPGRADE_FW_BIN2时,表示升级固件到分区2
|
||||
*/
|
||||
unsigned int HILINK_OtaAdapterGetUpdateIndex(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterGetUpdateIndex start\r\n");
|
||||
return UPGRADE_FW_BIN1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 擦除需要升级的分区
|
||||
* size表示需要擦除的分区大小
|
||||
* 返回值是ILINK_OK时,表示擦除成功
|
||||
* 返回值是HILINK_ERROR时,表示擦除失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashErase(unsigned int size)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashErase start size=%d\r\n",size);
|
||||
return IoTFlashErase(DOWNLOAD_PATITION_ADDR,DOWNLOAD_PATITION_LEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* 升级数据写入升级的分区
|
||||
* buf表示待写入数据
|
||||
* bufLen表示待写入数据的长度
|
||||
* 返回值是HILINK_OK时,表示写入成功
|
||||
* 返回值是HILINK_ERROR时,表示写入失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int bufLen)
|
||||
{
|
||||
//printf("HILINK_OtaAdapterFlashWrite start\r\n");
|
||||
#if 1
|
||||
int ret;
|
||||
if (bufLen == 0)
|
||||
{
|
||||
return HILINK_OK;
|
||||
}
|
||||
if (buf == NULL)
|
||||
{
|
||||
return HILINK_ERROR;
|
||||
}
|
||||
|
||||
ret = IoTFlashWrite(DOWNLOAD_PATITION_ADDR + write_length, bufLen, buf, 0);
|
||||
|
||||
write_length += bufLen;
|
||||
if(ret == 0)
|
||||
return HILINK_OK;
|
||||
else
|
||||
return HILINK_ERROR;
|
||||
#else
|
||||
return HILINK_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 读取升级分区数据
|
||||
* offset表示读写偏移
|
||||
* buf表示输出数据的内存地址
|
||||
* bufLen表示输出数据的内存长度
|
||||
* 返回值是HILINK_OK时,表示读取成功
|
||||
* 返回值是HILINK_ERROR时,表示读取失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int bufLen)
|
||||
{
|
||||
//printf("HILINK_OtaAdapterFlashRead start\r\n");
|
||||
#if 1
|
||||
int ret;
|
||||
if ( (buf == NULL) || (bufLen == 0))
|
||||
{
|
||||
return HILINK_ERROR;
|
||||
}
|
||||
ret = IoTFlashRead(DOWNLOAD_PATITION_ADDR + offset, bufLen, buf);
|
||||
|
||||
if(ret == 0)
|
||||
return HILINK_OK;
|
||||
else
|
||||
return HILINK_ERROR;
|
||||
#else
|
||||
return HILINK_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* 分区升级结束
|
||||
* 返回值是true时,表示结束正常
|
||||
* 返回值是false时,表示结束异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashFinish(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashFinish start\r\n");
|
||||
IoTFlashDeinit();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 获取升级区间最大长度 */
|
||||
unsigned int HILINK_OtaAdapterFlashMaxSize(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashMaxSize start\r\n");
|
||||
|
||||
return DOWNLOAD_PATITION_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据标志重启模组
|
||||
* flag表示重启标志
|
||||
* 当flag是RESTART_FLAG_NOW时,表示只有MCU升级时立即重启
|
||||
* 当flag是RESTART_FLAG_LATER时,表示有模组时切换分区后再重启
|
||||
*/
|
||||
void HILINK_OtaAdapterRestart(int flag)
|
||||
{
|
||||
printf("HILINK_OtaAdapterRestart start\r\n");
|
||||
reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 开始模组升级
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将开始启动升级流程
|
||||
* 返回值是RETURN_ERROR时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:在手动场景场景下,HiLink SDK在接收到用户发出的升级指令后,将直接调用此接口;
|
||||
* 在自动升级场景下,当HiLink SDK在调用HilinkGetRebootFlag接口返回值是MODULE_CAN_REBOOT时,HiLink SDK将调用此接口。
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_OtaStartProcess(int type)
|
||||
{
|
||||
printf("HILINK_OtaStartProcess start type =%d\r\n",type);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 模组升级结束
|
||||
* status表示升级结果
|
||||
* 当status是100时,表示升级成功
|
||||
* 当status不是100时,表示升级失败
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将置升级标志或切换运行区标志
|
||||
* 返回值不是RETURN_OK时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:HiLink SDK在将固件写入到OTA升级区后,且完整性校验通过后,将调用厂商适配的此接口;
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等;升级类型是否为自动升级可参考接口HilinkOtaStartProcess的参数type的描述。
|
||||
*/
|
||||
int HILINK_OtaEndProcess(int status)
|
||||
{
|
||||
printf("HILINK_OtaEndProcess start status=%d\r\n",status);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断模组是否能立即升级并重启
|
||||
* 返回值是MODULE_CAN_REBOOT时,表示模组可以立即升级并重启,HiLink SDK将开始自动升级流程。
|
||||
* 返回值是MODULE_CANNOT_REBOOT时,表示模组不能立即升级并重启,HiLink SDK将不进行本次自动升级流程。
|
||||
* 注意:在用户同意设备可以自动升级的情况下,HiLink SDK调用此接口获取设备当前业务状态下,模组是否可以立即升级并重启的标志。
|
||||
* 只有当设备处于业务空闲状态时,接口才可以返回MODULE_CAN_REBOOT。
|
||||
* 当设备处于业务非空闲状态时,接口返回MODULE_CANNOT_REBOOT。
|
||||
*/
|
||||
int HILINK_GetRebootFlag(void)
|
||||
{
|
||||
printf("HILINK_GetRebootFlag start\r\n");
|
||||
return MODULE_CAN_REBOOT;
|
||||
}
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本升级
|
||||
* 检测到的版本,sdk将通过cb回调函数触发升级
|
||||
*/
|
||||
void HILINK_TrigOtaSelfUpdate(TrigSelfUpdateCb cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
|
||||
* Description: 外挂MCU升级适配实现 (需设备厂商实现)
|
||||
*/
|
||||
|
||||
#include "hilink_open_ota_mcu_adapter.h"
|
||||
|
||||
/*
|
||||
* 获取MCU当前版本
|
||||
* version表示版本字符串
|
||||
* inLen表示输入字符串长度
|
||||
* outLen表示输出字符串长度
|
||||
* 返回值是RETURN_OK时,表示获取成功
|
||||
* 返回值是RETURN_ERROR_NO_MCU时,表示没有MCU
|
||||
* 返回值是RETURN_ERROR时,表示获取失败
|
||||
* 返回值是RETURN_MCU_NO_NEED_OTA时,表示不需要MCU升级
|
||||
* 注意:如果获取不到MCU的版本,则不对MCU进行升级。
|
||||
* 建议厂商在MCU正常启动后,或升级启动后,就将MCU的版本号传递给模组,确保模组可以获取到MCU的版本。
|
||||
*/
|
||||
int HILINK_GetMcuVersion(char *version, unsigned int inLen, unsigned int *outLen)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知MCU固件传输的状态
|
||||
* flag表示升级流程标志
|
||||
* 当flag是START_SEND_DATA时,表示通知模组即将开始发送MCU固件数据包
|
||||
* 当flag是STOP_SEND_DATA时,表示通知模组完整的MCU固件包已发送完成
|
||||
* 当flag是SEND_DATA_ERROR时,表示通知模组本次MCU固件升级异常终止
|
||||
* len表示MCU固件包的大小
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,表示处理失败,HiLink SDK将终止本次MCU升级流程
|
||||
* 注意:当flag是STOP_SEND_DATA时,此接口需返回MCU侧固件升级的结果;当flag是其它值时,需返回接口接收到此消息后的处理结果。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_NotifyOtaStatus(int flag, unsigned int len, unsigned int type)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知厂商发送MCU固件文件数据
|
||||
* data表示发送的数据
|
||||
* len表示发送的数据的长度
|
||||
* offset表示发送的数据起始位置相对于完整固件包的偏移量
|
||||
* 此接口需要返回MCU接收这部分数据的处理结果
|
||||
* 返回值是RETURN_OK时,模组将通知的数据正确发送给MCU,且MCU正确处理发送的数据,HiLink SDK将继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,模组或MCU未能正常处理通知的MCU的固件文件数据,HiLink SDK将终止本次MCU固件升级流程
|
||||
*/
|
||||
int HILINK_NotifyOtaData(const unsigned char *data, unsigned int len, unsigned int offset)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#import("//applications/iot_solution/device.gni")
|
||||
|
||||
oem_common_deps = [
|
||||
# "//build/lite/config/component/cJSON:cjson_shared",
|
||||
# "//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
|
||||
config("oem_common_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/cJSON/",
|
||||
"//third_party/mbedtls/include",
|
||||
"//kernel/liteos_m/components/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
# "//device/asr/asr582x/drivers/kv/include/",
|
||||
]
|
||||
defines = []
|
||||
}
|
||||
|
||||
static_library("oem_auth_result_storage") {
|
||||
sources = [ "src/oem_auth_result_storage.c" ]
|
||||
configs += [ ":oem_common_config" ]
|
||||
deps = oem_common_deps
|
||||
}
|
||||
|
||||
static_library("oem_auth_config") {
|
||||
sources = [ "src/oem_auth_config.c" ]
|
||||
configs += [ ":oem_common_config" ]
|
||||
deps = oem_common_deps
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: interface file for kitframework client
|
||||
* Author: yangzuxun
|
||||
* Create: 2020-07-20
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_KIT_FRAMEWORK_CLIENT_H
|
||||
#define HOS_LITE_KIT_FRAMEWORK_CLIENT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
// request auth result
|
||||
#define ERR_OK 0
|
||||
#define SERVICE_UNAVAILABLE (-1)
|
||||
#define INVALID_PARAM (-2)
|
||||
|
||||
#define PASS 0
|
||||
#define FAIL (-1)
|
||||
#define UNKNOWN (-2)
|
||||
|
||||
// define authentication control policy
|
||||
#define POLICY_ALERT (0x1 << 0) // 警告,kit自行决定
|
||||
#define POLICY_DENY (0x1 << 1) // 拒绝
|
||||
#define POLICY_PASS (0x1 << 2) // 放通
|
||||
#define POLICY_INVISBLE (0x1 << 3) // 设备不可见
|
||||
|
||||
// kit id
|
||||
#define DV_KIT "DvKit"
|
||||
#define CAST_KIT "CastKit"
|
||||
#define HI_LINK "HiLinkKit"
|
||||
#define HI_CAR "HiCarKit"
|
||||
#define SHARE "ShareKit"
|
||||
#define MEET_TIME "MeetTimeKit"
|
||||
#define ONE_HOP "OneHopKit"
|
||||
#define ONE_TAG "OneTagKit"
|
||||
|
||||
// CheckModuleValid return value
|
||||
#define RET_OK 1
|
||||
#define RET_FALSE 0
|
||||
#define RET_INVALID (-1)
|
||||
|
||||
typedef enum {
|
||||
TYPE_AA, // hap or static form
|
||||
TYPE_DEBUG, // debug version
|
||||
TYPE_BDREPORT, // big data report module
|
||||
TYPE_D2D, // D2D module
|
||||
TYPE_D2C, // D2C module
|
||||
} CheckType;
|
||||
|
||||
typedef struct AuthStatus AuthStatus;
|
||||
typedef void (*IAuthResultCallback)(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to initial the authtication client and connect to the
|
||||
* kit server, and return the connect status. The function must be called before
|
||||
* RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback).
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
* @return error_code: REQ_OK or SERVICE_UNAVAILABLE or INVALID_PARAM
|
||||
*/
|
||||
int32_t CreateKitFrameworkClient(const char* kitId);
|
||||
|
||||
/**
|
||||
* @brief The function is used to trigger device auth, and return the auth result.
|
||||
* The caller can only call the function without calling CreateKitFrameworkClient(const char* kitId) before.
|
||||
* @param networkId: the name defined in soft-bus, NULL for local device.
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
* @param callback: the Auth check result callback.
|
||||
* @return error_code: REQ_OK or SERVICE_UNAVAILABLE or INVALID_PARAM
|
||||
*/
|
||||
int32_t RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback);
|
||||
|
||||
/**
|
||||
* @brief The function is used to close the connection of kit server and release the client.
|
||||
* The function must be called after
|
||||
* RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback).
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
*/
|
||||
void CloseKitFrameworkClient(const char* kitId);
|
||||
|
||||
/**
|
||||
* @brief The function is used to check the type whether exists or not
|
||||
* @param type: the check module type.
|
||||
* @return error_code: RET_OK or RET_FALSE or RET_INVALID
|
||||
*/
|
||||
int32_t CheckModuleValid(CheckType type);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get device auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of device.
|
||||
*/
|
||||
int32_t GetDeviceStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get system auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of system.
|
||||
*/
|
||||
int32_t GetSystemStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get kit auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of kit.
|
||||
*/
|
||||
int32_t GetKitStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get kit auth policy;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth policy of kit.
|
||||
*/
|
||||
int32_t GetAuthPolicy(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get ticket;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return NULL or ticket , max size is 256.
|
||||
*/
|
||||
const char* GetTicket(const AuthStatus* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: headfile of oem_auth_config
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_OEM_AUTH_CONFIG_H
|
||||
#define HOS_LITE_OEM_AUTH_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "mbedtls/x509_crt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief read authentication's server info from device which implemented by OEM.
|
||||
* format: server1:port1;server2:port2; ...
|
||||
* @param port: pointer of server info's buffer.
|
||||
* @param len: length of server info's buffer, max value is 256.
|
||||
* The max length for signal NV srtuct is 252 Bytes, so please be careful if the server info is save as NV.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadAuthServerInfo(char* buff, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief load kit's id and verison information from device which implemented by OEM.
|
||||
* @return char* not NULL means load succeed, NULL is means OEM haven't set kit infos or no others kit to authenticate
|
||||
* example : NULL means no others kit
|
||||
* "{\"KitInfos\":[]}" means no others kit
|
||||
* "{\"KitInfos\":[{\"HiLinkKit\":\"1.0.0\"},{\"DvKit\":\"1.0.1\"}]}" means with HiLink and DvKit
|
||||
*/
|
||||
char* OEMLoadKitInfos(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HOS_LITE_OEM_AUTH_CONFIG_H */
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: headfile of oem_auth_result_storage
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
#ifndef HOS_LITE_OEM_AUTH_RESULT_STORAGE_H
|
||||
#define HOS_LITE_OEM_AUTH_RESULT_STORAGE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief check whether the temperature of the device's flash chip is over limit or not.
|
||||
* @return true is over limit.
|
||||
*/
|
||||
bool OEMIsOverTemperatureLimit(void);
|
||||
|
||||
/**
|
||||
* @brief check reset flag is exist or not which implemented by OEM.
|
||||
* @return true is reset flag existed, false is not.
|
||||
*/
|
||||
bool OEMIsResetFlagExist(void);
|
||||
|
||||
/**
|
||||
* @brief create reset flag in device which implemented by OEM.
|
||||
* @return 0 is create succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMCreateResetFlag(void);
|
||||
|
||||
/**
|
||||
* @brief delete reset flag in device which implemented by OEM.
|
||||
* @return 0 is create succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteResetFlag(void);
|
||||
|
||||
/**
|
||||
* @brief check auth status file is exist or not which implemented by OEM.
|
||||
* @return true is auth status file existed, false is not.
|
||||
*/
|
||||
bool OEMIsAuthStatusExist(void);
|
||||
|
||||
/**
|
||||
* @brief write auth status to device which implemented by OEM.
|
||||
* @param data: pointer of data which to be written.
|
||||
* @param len: length of data which to be written.
|
||||
* @return 0 is written succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMWriteAuthStatus(const char* data, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief read auth status from device which implemented by OEM.
|
||||
* @param buffer: pointer of auth status's buffer.
|
||||
* @param bufferLen: length of auth status's buffer.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadAuthStatus(char* buffer, uint32_t bufferLen);
|
||||
|
||||
/**
|
||||
* @brief delete auth status file from device which implemented by OEM.
|
||||
* @return 0 is delete succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteAuthStatus(void);
|
||||
|
||||
/**
|
||||
* @brief get auth status's content size from device which implemented by OEM.
|
||||
* @param len: pointer of auth status's content size.
|
||||
* @return 0 is succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMGetAuthStatusFileSize(uint32_t* len);
|
||||
|
||||
/**
|
||||
* @brief check ticket file is exist or not which implemented by OEM.
|
||||
* @return true is ticket file existed, false is not.
|
||||
*/
|
||||
bool OEMIsTicketExist(void);
|
||||
|
||||
/**
|
||||
* @brief write ticket to device which implemented by OEM.
|
||||
* @param data: pointer of data which to be written.
|
||||
* @param len: length of data which to be written.
|
||||
* @return 0 is written succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMWriteTicket(const char* data, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief read ticket from device which implemented by OEM.
|
||||
* @param buffer: pointer of ticket's buffer.
|
||||
* @param bufferLen: length of ticket's buffer.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadTicket(char* buffer, uint32_t bufferLen);
|
||||
|
||||
/**
|
||||
* @brief delete ticket file from device which implemented by OEM.
|
||||
* @return 0 is delete succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteTicket(void);
|
||||
|
||||
/**
|
||||
* @brief get ticket's content size from device which implemented by OEM.
|
||||
* @param len: pointer of ticket's content size.
|
||||
* @return 0 is succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMGetTicketFileSize(uint32_t* len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HOS_LITE_OEM_AUTH_RESULT_STORAGE_H */
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: implement of oem_auth_config
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#include "oem_auth_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#define HCS_HILINKKIT
|
||||
#define KIT_ID_LEN 40
|
||||
|
||||
typedef const char *(*KitGetVerFunc)();
|
||||
|
||||
typedef struct KitGetVerInfo
|
||||
{
|
||||
char kitId[KIT_ID_LEN + 1];
|
||||
KitGetVerFunc kitGetVerFunc;
|
||||
} KitGetVerInfo;
|
||||
|
||||
#ifdef HCS_DVKIT
|
||||
extern const char *DvKit_GetVersion();
|
||||
#endif
|
||||
|
||||
#ifdef HCS_HILINKKIT
|
||||
// extern const char* HiLinkKit_GetVersion();
|
||||
const char *HiLinkKit_GetVersion()
|
||||
{
|
||||
return "1.0.0";
|
||||
}
|
||||
#endif
|
||||
|
||||
KitGetVerInfo g_kitGetVerInfo[] = {
|
||||
#ifdef HCS_DVKIT
|
||||
{"DvKit", DvKit_GetVersion},
|
||||
#endif
|
||||
#ifdef HCS_HILINKKIT
|
||||
{"HiLinkKit", HiLinkKit_GetVersion},
|
||||
#endif
|
||||
{0, NULL}};
|
||||
#define TOTAL_TIMEOUT 10000
|
||||
#define KIT_INFO_JSON_KEY "KitInfos"
|
||||
uint32_t OEMGetTotalTimeout()
|
||||
{
|
||||
return TOTAL_TIMEOUT;
|
||||
}
|
||||
|
||||
int32_t OEMReadAuthServerInfo(char *buff, uint32_t len)
|
||||
{
|
||||
if (buff == NULL || len == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *OEMLoadKitInfos(void)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
if (root == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
cJSON *infos = cJSON_CreateArray();
|
||||
if (infos == NULL)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint32_t kitCount = sizeof(g_kitGetVerInfo) / sizeof(KitGetVerInfo);
|
||||
for (uint32_t i = 0; i < kitCount; i++)
|
||||
{
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
if (obj == NULL)
|
||||
{
|
||||
printf("OEM Adapter: Create json object failed\n");
|
||||
continue;
|
||||
}
|
||||
const char *key = g_kitGetVerInfo[i].kitId;
|
||||
KitGetVerFunc kitGetVerFunc = g_kitGetVerInfo[i].kitGetVerFunc;
|
||||
if (key == NULL || strlen(key) == 0 || kitGetVerFunc == NULL)
|
||||
{
|
||||
cJSON_Delete(obj);
|
||||
continue;
|
||||
}
|
||||
const char *value = (kitGetVerFunc)();
|
||||
if (value == NULL || strlen(value) == 0 || cJSON_AddStringToObject(obj, key, value) == NULL)
|
||||
{
|
||||
printf("OEM Adapter: Add kit info %s to json object failed\n", key);
|
||||
cJSON_Delete(obj);
|
||||
continue;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(infos, obj))
|
||||
{
|
||||
cJSON_Delete(obj);
|
||||
printf("OEM Adapter: Add kit info %s to json array failed\n", key);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cJSON_AddItemToObject(root, KIT_INFO_JSON_KEY, infos))
|
||||
{
|
||||
printf("OEM Adapter: Add kit infos to json object failed\n");
|
||||
cJSON_Delete(infos);
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
char *result = cJSON_PrintUnformatted(root);
|
||||
cJSON_Delete(root);
|
||||
return result;
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: implement of oem_auth_result_storage
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#include "oem_auth_result_storage.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "utils_file.h"
|
||||
|
||||
#define RESET_FILE_NAME "auth_reset"
|
||||
#define TICKET_FILE_NAME "auth_ticket"
|
||||
#define AUTH_STATS_FILE_NAME "auth_authstats"
|
||||
|
||||
#define WRITE_FLASH_MAX_TEMPERATURE 80
|
||||
static const uint32_t MAX_FILE_BYTES_LIMIT = 5120;
|
||||
|
||||
bool OEMIsOverTemperatureLimit(void)//???¨¨?D?¦Ì?D??
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsFileExist(const char* path)
|
||||
{
|
||||
printf("IsFileExist start path=%s\r\n",path);
|
||||
if(path == NULL)
|
||||
return false;
|
||||
int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
(void)UtilsFileClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t CreateFile(const char* path)
|
||||
{
|
||||
printf("CreateFile start path=%s\r\n",path);
|
||||
if(path == NULL)
|
||||
return false;
|
||||
int32_t fd = UtilsFileOpen(path, O_CREAT_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
(void)UtilsFileClose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int32_t WriteFile(const char* path,const char* data,uint32_t datalen,int flag)
|
||||
{
|
||||
printf("WriteFile start path=%s\r\n",path);
|
||||
if(path == NULL || data == NULL || datalen == 0)
|
||||
{
|
||||
printf("WriteFile data invalid\r\n");
|
||||
return -1;
|
||||
}
|
||||
if(datalen > MAX_FILE_BYTES_LIMIT)
|
||||
{
|
||||
printf("WriteFile data over limit\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(OEMIsOverTemperatureLimit())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int32_t fd = UtilsFileOpen(path, flag, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("WriteFile open failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if(UtilsFileWrite(fd, data, datalen) != datalen)
|
||||
{
|
||||
printf("WriteFile write failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)UtilsFileClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadFile(const char* path,const char* buffer,uint32_t bufferlen)
|
||||
{
|
||||
printf("ReadFile start path=%s\r\n",path);
|
||||
if(path == NULL || buffer == NULL || bufferlen == 0)
|
||||
{
|
||||
printf("ReadFile data invalid\r\n");
|
||||
return -1;
|
||||
}
|
||||
if(!IsFileExist(path))
|
||||
{
|
||||
printf("ReadFile file not exsit\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t filesize = 0;
|
||||
if(UtilsFileStat(path,&filesize) != 0)
|
||||
{
|
||||
printf("ReadFile stat file failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(filesize > bufferlen)
|
||||
{
|
||||
printf("ReadFile read data over buffer lenth\r\n");
|
||||
return -1;
|
||||
}
|
||||
int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("ReadFile open failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if(UtilsFileRead(fd, buffer, filesize) != filesize)
|
||||
{
|
||||
printf("ReadFile read data failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)UtilsFileClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t DeleteFile(const char* path)
|
||||
{
|
||||
UtilsFileDelete(path);
|
||||
}
|
||||
|
||||
bool OEMIsResetFlagExist(void)
|
||||
{
|
||||
return IsFileExist(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMCreateResetFlag(void)
|
||||
{
|
||||
return CreateFile(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteResetFlag(void)
|
||||
{
|
||||
return DeleteFile(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
bool OEMIsAuthStatusExist(void)
|
||||
{
|
||||
return IsFileExist(AUTH_STATS_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMWriteAuthStatus(const char* data, uint32_t len)
|
||||
{
|
||||
if(data == NULL || len == 0)
|
||||
return -1;
|
||||
|
||||
return WriteFile(AUTH_STATS_FILE_NAME,data,len,O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS);
|
||||
}
|
||||
|
||||
int32_t OEMReadAuthStatus(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
if(buffer == NULL || bufferLen == 0)
|
||||
return -1;
|
||||
|
||||
return ReadFile(AUTH_STATS_FILE_NAME,buffer,bufferLen);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteAuthStatus(void)
|
||||
{
|
||||
return DeleteFile(AUTH_STATS_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMGetAuthStatusFileSize(uint32_t* len)
|
||||
{
|
||||
printf("OEMGetAuthStatusFileSize len=%p\r\n",len);
|
||||
if(len == NULL)
|
||||
return -1;
|
||||
|
||||
return UtilsFileStat(AUTH_STATS_FILE_NAME,len);
|
||||
}
|
||||
|
||||
bool OEMIsTicketExist(void)
|
||||
{
|
||||
return IsFileExist(TICKET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMWriteTicket(const char* data, uint32_t len)
|
||||
{
|
||||
printf("OEMWriteTicket data=%s -- len=%d\r\n",data,len);
|
||||
if(data == NULL || len == 0)
|
||||
return -1;
|
||||
|
||||
return WriteFile(TICKET_FILE_NAME,data,len,O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS);
|
||||
}
|
||||
|
||||
int32_t OEMReadTicket(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
printf("OEMReadTicket buffer=%s -- bufferLen=%d\r\n",buffer,bufferLen);
|
||||
if(buffer == NULL || bufferLen == 0)
|
||||
return -1;
|
||||
|
||||
return ReadFile(TICKET_FILE_NAME,buffer,bufferLen);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteTicket(void)
|
||||
{
|
||||
return DeleteFile(TICKET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMGetTicketFileSize(uint32_t* len)
|
||||
{
|
||||
return UtilsFileStat(TICKET_FILE_NAME,len);
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
static_library("hal_sysparam") {
|
||||
sources = [ "hal_sys_param.c" ]
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
defines = [
|
||||
"INCREMENTAL_VERSION=\"${ohos_version}\"",
|
||||
"BUILD_TYPE=\"${ohos_build_type}\"",
|
||||
"BUILD_USER=\"${ohos_build_user}\"",
|
||||
"BUILD_TIME=\"${ohos_build_time}\"",
|
||||
"BUILD_HOST=\"${ohos_build_host}\"",
|
||||
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
|
||||
]
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
#include "hal_sys_param.h"
|
||||
|
||||
|
||||
#define PRD_Lamp_2HSB 1 /* DALEN product wifi+BLE +KIT */
|
||||
#define PRD_Lamp_2IES 2 /* DALEN product wifi+BLE +KIT */
|
||||
|
||||
|
||||
#define USING_PRODUCT_ID PRD_Lamp_2HSB
|
||||
|
||||
#if(USING_PRODUCT_ID == PRD_Lamp_2HSB)
|
||||
static const char OHOS_DEVICE_TYPE[] = {"Table Lamp"};
|
||||
static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
|
||||
static const char OHOS_MANUFACTURE[] = {"BEKEN"};
|
||||
static const char OHOS_BRAND[] = {"BEKEN"};
|
||||
static const char OHOS_MARKET_NAME[] = {"BK7231M-LIGHT"};
|
||||
static const char OHOS_PRODUCT_SERIES[] = {"light"};
|
||||
static const char OHOS_PRODUCT_MODEL[] = {"light-01"};
|
||||
static const char OHOS_SOFTWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"wifi:true,ble:true"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const char OHOS_ABI_LIST[] = {"riscv-liteos"};
|
||||
//static const char OHOS_SERIAL[] = {"C86000000001"};
|
||||
char OHOS_SERIAL[16] = {0};
|
||||
#elif(USING_PRODUCT_ID == PRD_Lamp_2IES)
|
||||
static const char OHOS_DEVICE_TYPE[] = {"Table Lamp"};
|
||||
static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
|
||||
static const char OHOS_MANUFACTURE[] = {"BEKEN"};
|
||||
static const char OHOS_BRAND[] = {"BEKEN"};
|
||||
static const char OHOS_MARKET_NAME[] = {"BK7235-LIGHT"};
|
||||
static const char OHOS_PRODUCT_SERIES[] = {"bk7235"};
|
||||
static const char OHOS_PRODUCT_MODEL[] = {"bk7235-002"};
|
||||
static const char OHOS_SOFTWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"wifi:true,ble:true"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const char OHOS_ABI_LIST[] = {"riscv-liteos"};
|
||||
|
||||
//static const char OHOS_SERIAL[] = {"123456789"};
|
||||
char OHOS_SERIAL[16] = {0};
|
||||
|
||||
#endif
|
||||
static const int OHOS_FIRST_API_VERSION = 1;
|
||||
|
||||
const char* HalGetDeviceType(void)
|
||||
{
|
||||
return OHOS_DEVICE_TYPE;
|
||||
}
|
||||
|
||||
const char* HalGetManufacture(void)
|
||||
{
|
||||
return OHOS_MANUFACTURE;
|
||||
}
|
||||
|
||||
const char* HalGetBrand(void)
|
||||
{
|
||||
return OHOS_BRAND;
|
||||
}
|
||||
|
||||
const char* HalGetMarketName(void)
|
||||
{
|
||||
return OHOS_MARKET_NAME;
|
||||
}
|
||||
|
||||
const char* HalGetProductSeries(void)
|
||||
{
|
||||
return OHOS_PRODUCT_SERIES;
|
||||
}
|
||||
|
||||
const char* HalGetProductModel(void)
|
||||
{
|
||||
return OHOS_PRODUCT_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetSoftwareModel(void)
|
||||
{
|
||||
return OHOS_SOFTWARE_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetHardwareModel(void)
|
||||
{
|
||||
return OHOS_HARDWARE_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetHardwareProfile(void)
|
||||
{
|
||||
return OHOS_HARDWARE_PROFILE;
|
||||
}
|
||||
char make_ohos_serial[16] = {0};
|
||||
#define in_range(c, lo, up) ((unsigned char)c >= lo && (unsigned char)c <= up)
|
||||
#define islower(c) in_range(c, 'a', 'z')
|
||||
#include "string.h"
|
||||
const char* HalGetSerial(void)
|
||||
{
|
||||
#if 1
|
||||
typedef int bk_err_t; /**< Return error code */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char mac_type_t;
|
||||
uint8_t mac_read[6];
|
||||
|
||||
extern bk_err_t bk_get_mac(uint8_t *mac, mac_type_t type);
|
||||
bk_get_mac(mac_read,0);
|
||||
os_snprintf(&make_ohos_serial[0],sizeof(make_ohos_serial),"%02x%02x%02x%02x%02x%02x",mac_read[0],mac_read[1],mac_read[2],mac_read[3],mac_read[4],mac_read[5]);
|
||||
|
||||
for(int i = 0; i<sizeof(make_ohos_serial);i++)
|
||||
{
|
||||
if(islower(make_ohos_serial[i]))
|
||||
make_ohos_serial[i] +='A' - 'a';
|
||||
}
|
||||
memcpy(OHOS_SERIAL,make_ohos_serial,strlen(make_ohos_serial)+1);
|
||||
#endif
|
||||
printf("OHOS_SERIAL=%s\r\n",OHOS_SERIAL);
|
||||
return OHOS_SERIAL;
|
||||
}
|
||||
|
||||
const char* HalGetBootloaderVersion(void)
|
||||
{
|
||||
return OHOS_BOOTLOADER_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetAbiList(void)
|
||||
{
|
||||
return OHOS_ABI_LIST;
|
||||
}
|
||||
|
||||
const char* HalGetDisplayVersion(void)
|
||||
{
|
||||
return OHOS_DISPLAY_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetIncrementalVersion(void)
|
||||
{
|
||||
return INCREMENTAL_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetBuildType(void)
|
||||
{
|
||||
return BUILD_TYPE;
|
||||
}
|
||||
|
||||
const char* HalGetBuildUser(void)
|
||||
{
|
||||
return BUILD_USER;
|
||||
}
|
||||
|
||||
const char* HalGetBuildHost(void)
|
||||
{
|
||||
return BUILD_HOST;
|
||||
}
|
||||
|
||||
const char* HalGetBuildTime(void)
|
||||
{
|
||||
return BUILD_TIME;
|
||||
}
|
||||
|
||||
int HalGetFirstApiVersion(void)
|
||||
{
|
||||
return OHOS_FIRST_API_VERSION;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
const.build.characteristics=****
|
||||
|
||||
const.product.manufacturer=****
|
||||
|
||||
const.product.brand=****
|
||||
|
||||
const.product.name=****
|
||||
|
||||
const.build.product=****
|
||||
|
||||
const.product.model=****
|
||||
|
||||
const.software.model=****
|
||||
|
||||
const.product.hardwareversion=****
|
||||
|
||||
const.product.hardwareprofile="aout:true,display:true"
|
||||
|
||||
const.ohos.serial=1234567890
|
||||
|
||||
const.product.bootloader.version=bootloader
|
||||
|
||||
const.product.cpu.abilist=****
|
||||
|
||||
const.product.software.version="OpenHarmony 1.0.1"
|
||||
|
||||
const.product.firstapiversion=1
|
||||
@@ -9,7 +9,8 @@
|
||||
# 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.
|
||||
# limitations under the License.
|
||||
import("${board_adapter_dir}/hals/sdk_dir.gni")
|
||||
|
||||
static_library("hal_token_static") {
|
||||
sources = [ "hal_token.c" ]
|
||||
@@ -17,7 +18,15 @@ static_library("hal_token_static") {
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
"//foundation/hilink/include",
|
||||
"${beken_sdk_dir}/include",
|
||||
"${beken_sdk_dir}/include/arch/compiler",
|
||||
"${beken_sdk_dir}/components/bk_cli/include",
|
||||
"${beken_sdk_dir}/components/bk_cli/include/bk_private",
|
||||
"//utils/native/lite/hals/file",
|
||||
"//applications/iot_solution/thing_model/WiFi",
|
||||
|
||||
]
|
||||
include_dirs += bk_hal_include_dirs
|
||||
|
||||
deps = []
|
||||
}
|
||||
+24
-18
@@ -1,11 +1,14 @@
|
||||
#include "hal_token.h"
|
||||
#include "bk_cli.h"
|
||||
#include "ohos_errno.h"
|
||||
#include "ohos_types.h"
|
||||
#include "hilink_device.h"
|
||||
#include "utils_file.h"
|
||||
#include "wlan_cli_pub.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "hal_file.h"
|
||||
#include <securec.h>
|
||||
#include "iot_device.h"
|
||||
|
||||
|
||||
#define TokenPathA "/usrdata/hilink/tokenA.cfg"
|
||||
@@ -37,11 +40,11 @@ static void SetTokenFlag(uint8_t flag[], uint32_t value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int OEMReadToken(char *token, unsigned int len)
|
||||
{
|
||||
int tokenAfd,tokenBfd;
|
||||
int tokenReadLen;
|
||||
(void) tokenReadLen;
|
||||
tokenAfd = HalFileOpen(TokenPathA , O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
if((tokenAfd < 0)&&(tokenBfd < 0)){
|
||||
@@ -88,6 +91,7 @@ static int OEMWriteToken(const char *token, unsigned int len)
|
||||
int tokenAfd,tokenBfd;
|
||||
int tokenAfileSize,tokenBfileSize;
|
||||
int tokenWriteLen;
|
||||
(void )tokenWriteLen;
|
||||
uint32_t flagA,flagB;
|
||||
|
||||
tokenAfileSize = FileSize(TokenPathA );
|
||||
@@ -99,7 +103,7 @@ static int OEMWriteToken(const char *token, unsigned int len)
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag(&tokenA_withFlag[TOKEN_SIZE],1);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],1);
|
||||
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenA_withFlag);
|
||||
@@ -126,7 +130,7 @@ static int OEMWriteToken(const char *token, unsigned int len)
|
||||
if(tokenBfd>=0){
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenB_withFlag, len, token, len);
|
||||
SetTokenFlag(&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
SetTokenFlag((uint8_t *)&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
tokenWriteLen = HalFileWrite(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenBfd);
|
||||
@@ -152,7 +156,7 @@ static int OEMWriteToken(const char *token, unsigned int len)
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag(&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenA_withFlag);
|
||||
@@ -184,14 +188,16 @@ static int OEMWriteToken(const char *token, unsigned int len)
|
||||
if(flagA <= flagB){
|
||||
if(tokenAfd>=0){
|
||||
flagA = flagB + 1;
|
||||
SetTokenFlag(&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
}
|
||||
}else{
|
||||
if(tokenBfd>=0){
|
||||
flagB = flagA + 1;
|
||||
SetTokenFlag(&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
(void)memcpy_s(tokenB_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
}
|
||||
@@ -209,17 +215,17 @@ static int OEMWriteToken(const char *token, unsigned int len)
|
||||
|
||||
static int OEMGetAcKey(char *acKey, unsigned int len)
|
||||
{
|
||||
memcpy(acKey,Ackey,len);
|
||||
extern unsigned char A_C[48];
|
||||
memcpy(acKey,A_C,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int OEMGetProdId(char *productId, unsigned int len)
|
||||
{
|
||||
memcpy(productId,PRODUCT_ID,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
//c35d6777954b439aaf2da4a1e3b1fe61
|
||||
static int OEMGetProdKey(char *productKey, unsigned int len)
|
||||
{
|
||||
memcpy(productKey,PRODUCT_KEY,len);
|
||||
@@ -238,7 +244,7 @@ int HalReadToken(char *token, unsigned int len)
|
||||
|
||||
int HalWriteToken(const char *token, unsigned int len)
|
||||
{
|
||||
if (token == NULL) {
|
||||
if ((token == NULL) ||(len==0)){
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
@@ -282,7 +288,7 @@ void token_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **ar
|
||||
if (os_strcmp(argv[2], "part1") == 0){
|
||||
if(strlen(argv[3]) <= TOKEN_SIZE){
|
||||
if(tokenbuf == NULL){
|
||||
tokenbuf = (char *)os_malloc(TOKEN_SIZE+1);
|
||||
tokenbuf = (char *)malloc(TOKEN_SIZE+1);
|
||||
}
|
||||
(void)memcpy_s(tokenbuf, TOKEN_SIZE, argv[3], strlen(argv[3]));
|
||||
token_pos = strlen(argv[3]);
|
||||
@@ -300,7 +306,7 @@ void token_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **ar
|
||||
}else{
|
||||
printf("token len valid.part1+part2 should be 151\r\n");
|
||||
}
|
||||
os_free(tokenbuf);
|
||||
free(tokenbuf);
|
||||
}
|
||||
|
||||
}else if (os_strcmp(argv[2], "local") == 0){
|
||||
@@ -312,7 +318,7 @@ void token_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **ar
|
||||
}
|
||||
}
|
||||
}else if(os_strcmp(argv[1], "r") == 0){
|
||||
char *tokenRbuf = (char *)os_malloc(TOKEN_SIZE+1);
|
||||
char *tokenRbuf = (char *)malloc(TOKEN_SIZE+1);
|
||||
HalReadToken(tokenRbuf,TOKEN_SIZE);
|
||||
char tmp_c;
|
||||
tmp_c = tokenRbuf[80];
|
||||
@@ -321,7 +327,7 @@ void token_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **ar
|
||||
tokenRbuf[80] = tmp_c;
|
||||
tokenRbuf[151] = '\0';
|
||||
printf("%s\r\n",&tokenRbuf[80]); //printf part2
|
||||
os_free(tokenRbuf);
|
||||
free(tokenRbuf);
|
||||
|
||||
}
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
# LOSCFG_COMPILE_OPTIMIZE is not set
|
||||
# LOSCFG_COMPILE_LTO is not set
|
||||
LOSCFG_PLATFORM_QEMU_RISCV32_VIRT=y
|
||||
LOSCFG_SOC_SERIES_BK7235=y
|
||||
# LOSCFG_POSIX_SEM_API is not set
|
||||
# LOSCFG_POSIX_MQUEUE_API is not set
|
||||
# LOSCFG_POSIX_PIPE_API is not set
|
||||
# LOSCFG_POSIX_SIGNAL_API is not set
|
||||
# LOSCFG_FS_VFS is not set
|
||||
# LOSCFG_PLATFORM_ADAPT is not set
|
||||
# LOSCFG_ENABLE_MAGICKEY is not set
|
||||
# LOSCFG_DEBUG_VERSION is not set
|
||||
LOSCFG_DRIVERS_HDF=y
|
||||
LOSCFG_DRIVERS_HDF_PLATFORM=y
|
||||
LOSCFG_CC_NO_STACKPROTECTOR=y
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"parts": {
|
||||
"product_test_xts_part1": {
|
||||
"module_list": [
|
||||
"//vendor/beken/test_xts_part1:test_xts_part1"
|
||||
]
|
||||
}
|
||||
},
|
||||
"subsystem": "product_test_xts_part1"
|
||||
}
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
group("test_xts_part2") {
|
||||
deps = [
|
||||
|
||||
"//test/xts/tools/lite/hctest:hctest",
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"product_name": "xts_test_part2",
|
||||
"ohos_version": "OpenHarmony 3.0",
|
||||
"type": "mini",
|
||||
"version": "3.0",
|
||||
"device_company": "beken",
|
||||
"board": "bk7235x",
|
||||
"kernel_type": "liteos_m",
|
||||
"kernel_version": "3.0",
|
||||
"subsystems": [
|
||||
{
|
||||
"subsystem": "kernel",
|
||||
"components": [
|
||||
{
|
||||
"component": "liteos_m",
|
||||
"features": [
|
||||
"ohos_kernel_liteos_m_lwip_path = \"//device/soc/beken/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2\""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "hiviewdfx",
|
||||
"components": [
|
||||
{ "component": "hilog_lite", "features":[] },
|
||||
{ "component": "hievent_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "systemabilitymgr",
|
||||
"components": [
|
||||
{ "component": "samgr_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "communication",
|
||||
"components": [
|
||||
{ "component": "wifi_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "commonlibrary",
|
||||
"components": [
|
||||
{ "component": "file", "features":[] },
|
||||
{ "component": "timer_task", "features":[] },
|
||||
{ "component": "kal_timer", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "startup",
|
||||
"components": [
|
||||
{ "component": "bootstrap_lite", "features":[] },
|
||||
{ "component": "init_lite", "features":["enable_ohos_startup_init_feature_begetctl_liteos = true"] },
|
||||
{ "component": "syspara_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "security",
|
||||
"components": [
|
||||
{ "component": "huks", "features":
|
||||
[
|
||||
"disable_huks_binary = true",
|
||||
"disable_authenticate = true",
|
||||
"huks_use_lite_storage = true",
|
||||
"huks_use_hardware_root_key = true",
|
||||
"huks_config_file = \"hks_config_lite.h\"",
|
||||
"ohos_security_huks_mbedtls_porting_path = \"//device/soc/beken/bk7235/liteos_m/components/mbedtls\""
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "iothardware",
|
||||
"components": [
|
||||
{ "component": "peripheral", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "xts",
|
||||
"components": [
|
||||
{"component": "xts_acts", "features":
|
||||
[
|
||||
"enable_ohos_test_xts_acts_use_thirdparty_lwip = true",
|
||||
"build_xts = true"
|
||||
]
|
||||
},
|
||||
{ "component": "xts_tools", "features":[] }
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
"third_party_dir": "//third_party",
|
||||
"product_adapter_dir": "//vendor/beken/test_xts_part2/hals",
|
||||
"xts_list": [
|
||||
{
|
||||
"enable": "true",
|
||||
"xts_modules": [
|
||||
"ActsKvStoreTest",
|
||||
"ActsDfxFuncTest",
|
||||
"ActsHieventLiteTest",
|
||||
"ActsSamgrTest",
|
||||
"ActsParameterTest",
|
||||
"ActsWifiServiceTest",
|
||||
"ActsWifiIotTest",
|
||||
"ActsBootstrapTest"
|
||||
]
|
||||
}
|
||||
],
|
||||
"tests_list": [
|
||||
{
|
||||
"enable": "false"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
harmonyos_connect_package_path = "//vendor/huawei/harmonyos_connect"
|
||||
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
ohos_type = "mini"
|
||||
} else if (ohos_kernel_type == "liteos_a") {
|
||||
ohos_type = "small"
|
||||
} else if (ohos_kernel_type == "linux") {
|
||||
ohos_type = "standard"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//applications/iot_solution/device.gni")
|
||||
|
||||
static_library("ota_update_adapter") {
|
||||
sources = [
|
||||
"src/hilink_open_ota_adapter.c",
|
||||
"src/hilink_open_ota_mcu_adapter.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
# "//device/asr/asr582x/drivers/ota"
|
||||
]
|
||||
|
||||
deps = [ "$ohos_vendor_adapter_dir/hals/update:hal_update_static" ]
|
||||
}
|
||||
Executable
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2021. All rights reserved.
|
||||
* Description: OTA适配层接口(需设备厂商实现)
|
||||
*/
|
||||
#ifndef HILINK_OPEN_OTA_ADAPTER_H
|
||||
#define HILINK_OPEN_OTA_ADAPTER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* OTA升级分区1 */
|
||||
#ifndef UPGRADE_FW_BIN1
|
||||
#define UPGRADE_FW_BIN1 0x00
|
||||
#endif
|
||||
|
||||
/* OTA升级分区2 */
|
||||
#ifndef UPGRADE_FW_BIN2
|
||||
#define UPGRADE_FW_BIN2 0x01
|
||||
#endif
|
||||
|
||||
/* 只有MCU升级时立即重启 */
|
||||
#ifndef RESTART_FLAG_NOW
|
||||
#define RESTART_FLAG_NOW 0x01
|
||||
#endif
|
||||
|
||||
/* 有模组时切换分区后再重启 */
|
||||
#ifndef RESTART_FLAG_LATER
|
||||
#define RESTART_FLAG_LATER 0x02
|
||||
#endif
|
||||
|
||||
/* 模组可以重启 */
|
||||
#ifndef MODULE_CAN_REBOOT
|
||||
#define MODULE_CAN_REBOOT 0x01
|
||||
#endif
|
||||
|
||||
/* 模组不能重启 */
|
||||
#ifndef MODULE_CANNOT_REBOOT
|
||||
#define MODULE_CANNOT_REBOOT 0x00
|
||||
#endif
|
||||
|
||||
/* 手动升级 */
|
||||
#ifndef UPDATE_TYPE_MANUAL
|
||||
#define UPDATE_TYPE_MANUAL 0x00
|
||||
#endif
|
||||
|
||||
/* 自动升级 */
|
||||
#ifndef UPDATE_TYPE_AUTO
|
||||
#define UPDATE_TYPE_AUTO 0x01
|
||||
#endif
|
||||
|
||||
/* 返回正常 */
|
||||
#ifndef RETURN_OK
|
||||
#define RETURN_OK 0
|
||||
#endif
|
||||
/* 没有MCU */
|
||||
#ifndef RETURN_ERROR_NO_MCU
|
||||
#define RETURN_ERROR_NO_MCU (-1)
|
||||
#endif
|
||||
/* 返回其他错误 */
|
||||
#ifndef RETURN_ERROR
|
||||
#define RETURN_ERROR (-2)
|
||||
#endif
|
||||
/* MCU不需要升级 */
|
||||
#ifndef RETURN_MCU_NO_NEED_OTA
|
||||
#define RETURN_MCU_NO_NEED_OTA (-3)
|
||||
#endif
|
||||
|
||||
typedef void (*GetOtaVerCb)(const char *version);
|
||||
typedef void (*TrigSelfUpdateCb)(const char *url, const unsigned int size);
|
||||
|
||||
/*
|
||||
* Flash初始化
|
||||
* 返回值是true时,表示初始化正常
|
||||
* 返回值是false时,表示初始化异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashInit(void);
|
||||
|
||||
/*
|
||||
* 判断需要升级的分区
|
||||
* 返回值是UPGRADE_FW_BIN1时,表示升级固件到分区1
|
||||
* 返回值是UPGRADE_FW_BIN2时,表示升级固件到分区2
|
||||
*/
|
||||
unsigned int HILINK_OtaAdapterGetUpdateIndex(void);
|
||||
|
||||
/*
|
||||
* 擦除需要升级的分区
|
||||
* size表示需要擦除的分区大小
|
||||
* 返回值是0时,表示擦除成功
|
||||
* 返回值是-1时,表示擦除失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashErase(unsigned int size);
|
||||
|
||||
/*
|
||||
* 升级数据写入升级的分区
|
||||
* buf表示待写入数据
|
||||
* bufLen表示待写入数据的长度
|
||||
* 返回值是0时,表示写入成功
|
||||
* 返回值是-1时,表示写入失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int bufLen);
|
||||
|
||||
/*
|
||||
* 读取升级分区数据
|
||||
* offset表示读写偏移
|
||||
* buf表示输出数据的内存地址
|
||||
* bufLen表示输出数据的内存长度
|
||||
* 返回值是0时,表示读取成功
|
||||
* 返回值是-1时,表示读取失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int bufLen);
|
||||
|
||||
/*
|
||||
* 分区升级结束
|
||||
* 返回值是true时,表示结束正常
|
||||
* 返回值是false时,表示结束异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashFinish(void);
|
||||
|
||||
/* 获取升级区间最大长度 */
|
||||
unsigned int HILINK_OtaAdapterFlashMaxSize(void);
|
||||
|
||||
/*
|
||||
* 根据标志重启模组
|
||||
* flag表示重启标志
|
||||
* 当flag是RESTART_FLAG_NOW时,表示只有MCU升级时立即重启
|
||||
* 当flag是RESTART_FLAG_LATER时,表示有模组时切换分区后再重启
|
||||
*/
|
||||
void HILINK_OtaAdapterRestart(int flag);
|
||||
|
||||
/*
|
||||
* 开始模组升级
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将开始启动升级流程
|
||||
* 返回值是RETURN_ERROR时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:在手动场景场景下,HiLink SDK在接收到用户发出的升级指令后,将直接调用此接口;
|
||||
* 在自动升级场景下,当HiLink SDK在调用HilinkGetRebootFlag接口返回值是MODULE_CAN_REBOOT时,HiLink SDK将调用此接口。
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_OtaStartProcess(int type);
|
||||
|
||||
/*
|
||||
* 模组升级结束
|
||||
* status表示升级结果
|
||||
* 当status是100时,表示升级成功
|
||||
* 当status不是100时,表示升级失败
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将置升级标志或切换运行区标志
|
||||
* 返回值不是RETURN_OK时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:HiLink SDK在将固件写入到OTA升级区后,且完整性校验通过后,将调用厂商适配的此接口;
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等;升级类型是否为自动升级可参考接口HilinkOtaStartProcess的参数type的描述。
|
||||
*/
|
||||
int HILINK_OtaEndProcess(int status);
|
||||
|
||||
/*
|
||||
* 判断模组是否能立即升级并重启
|
||||
* 返回值是MODULE_CAN_REBOOT时,表示模组可以立即升级并重启,HiLink SDK将开始自动升级流程。
|
||||
* 返回值是MODULE_CANNOT_REBOOT时,表示模组不能立即升级并重启,HiLink SDK将不进行本次自动升级流程。
|
||||
* 注意:在用户同意设备可以自动升级的情况下,HiLink SDK调用此接口获取设备当前业务状态下,模组是否可以立即升级并重启的标志。
|
||||
* 只有当设备处于业务空闲状态时,接口才可以返回MODULE_CAN_REBOOT。
|
||||
* 当设备处于业务非空闲状态时,接口返回MODULE_CANNOT_REBOOT。
|
||||
*/
|
||||
int HILINK_GetRebootFlag(void);
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本检测
|
||||
* 检测到的版本,sdk将通过cb回调函数上报。如果不需要获取版本号,则可将cb置空。
|
||||
* 上报的version如果为空,则未成功获取到新版本。
|
||||
* 注意:1、建议调用频次最多一天一次
|
||||
* 2、首次通过手机配网成功后不能调用,建议连云成功后至少5s后调用
|
||||
*/
|
||||
void HILINK_TrigOtaVersionCheck(GetOtaVerCb cb);
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本升级
|
||||
* 检测到的版本,sdk将通过cb回调函数触发升级
|
||||
*/
|
||||
void HILINK_TrigOtaSelfUpdate(TrigSelfUpdateCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
|
||||
* Description: MCU OTA适配层接口(需设备厂商实现)
|
||||
*/
|
||||
#ifndef HILINK_OPEN_OTA_MCU_ADAPTER_H
|
||||
#define HILINK_OPEN_OTA_MCU_ADAPTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 返回正常 */
|
||||
#ifndef RETURN_OK
|
||||
#define RETURN_OK 0
|
||||
#endif
|
||||
|
||||
/* 没有MCU */
|
||||
#ifndef RETURN_ERROR_NO_MCU
|
||||
#define RETURN_ERROR_NO_MCU (-1)
|
||||
#endif
|
||||
|
||||
/* MCU返回其他错误 */
|
||||
#ifndef RETURN_ERROR
|
||||
#define RETURN_ERROR (-2)
|
||||
#endif
|
||||
|
||||
/* MCU不需要升级 */
|
||||
#ifndef RETURN_MCU_NO_NEED_OTA
|
||||
#define RETURN_MCU_NO_NEED_OTA (-3)
|
||||
#endif
|
||||
|
||||
/* 手动升级 */
|
||||
#ifndef UPDATE_TYPE_MANUAL
|
||||
#define UPDATE_TYPE_MANUAL 0x00
|
||||
#endif
|
||||
|
||||
/* 自动升级 */
|
||||
#ifndef UPDATE_TYPE_AUTO
|
||||
#define UPDATE_TYPE_AUTO 0x01
|
||||
#endif
|
||||
|
||||
/* 开始发送MCU数据 */
|
||||
#ifndef START_SEND_DATA
|
||||
#define START_SEND_DATA 0
|
||||
#endif
|
||||
|
||||
/* 发送MCU数据结束 */
|
||||
#ifndef STOP_SEND_DATA
|
||||
#define STOP_SEND_DATA 1
|
||||
#endif
|
||||
|
||||
/* 异常终止 */
|
||||
#ifndef SEND_DATA_ERROR
|
||||
#define SEND_DATA_ERROR 2
|
||||
#endif
|
||||
|
||||
typedef int (*RptUpgProgressFlagCb)(void);
|
||||
|
||||
/*
|
||||
* 获取MCU当前版本
|
||||
* version表示版本字符串
|
||||
* inLen表示输入字符串长度
|
||||
* outLen表示输出字符串长度
|
||||
* 返回值是RETURN_OK时,表示获取成功
|
||||
* 返回值是RETURN_ERROR_NO_MCU时,表示没有MCU
|
||||
* 返回值是RETURN_ERROR时,表示获取失败
|
||||
* 注意:如果获取不到MCU的版本,则不对MCU进行升级。
|
||||
* 建议厂商在MCU正常启动后,或升级启动后,就将MCU的版本号传递给模组,确保模组可以获取到MCU的版本。
|
||||
*/
|
||||
int HILINK_GetMcuVersion(char *version, unsigned int inLen, unsigned int *outLen);
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知MCU固件传输的状态
|
||||
* flag表示升级流程标志
|
||||
* 当flag是START_SEND_DATA时,表示通知模组即将开始发送MCU固件数据包
|
||||
* 当flag是STOP_SEND_DATA时,表示通知模组完整的MCU固件包已发送完成
|
||||
* 当flag是SEND_DATA_ERROR时,表示通知模组本次MCU固件升级异常终止
|
||||
* len表示MCU固件包的大小
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,表示处理失败,HiLink SDK将终止本次MCU升级流程
|
||||
* 注意:当flag是STOP_SEND_DATA时,此接口需返回MCU侧固件升级的结果;当flag是其它值时,需返回接口接收到此消息后的处理结果。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_NotifyOtaStatus(int flag, unsigned int len, unsigned int type);
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知厂商发送MCU固件文件数据
|
||||
* data表示发送的数据
|
||||
* len表示发送的数据的长度
|
||||
* offset表示发送的数据起始位置相对于完整固件包的偏移量
|
||||
* 此接口需要返回MCU接收这部分数据的处理结果
|
||||
* 返回值是RETURN_OK时,模组将通知的数据正确发送给MCU,且MCU正确处理发送的数据,HiLink SDK将继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,模组或MCU未能正常处理通知的MCU的固件文件数据,HiLink SDK将终止本次MCU固件升级流程
|
||||
*/
|
||||
int HILINK_NotifyOtaData(const unsigned char *data, unsigned int len, unsigned int offset);
|
||||
|
||||
/*
|
||||
* 产品OTA升级时下载升级包进度为100%后会重启, APP上显示设备重启中
|
||||
* 然后等设备起来后上报进度0, APP上才会显示升级成功
|
||||
* 通过回调函数cb来设置Hilink Sdk被拉起后是否立即向APP上报进度0
|
||||
* cb返回1时hilink sdk被拉起后不会立即上报进度0,
|
||||
* 上报时机由产品自己决定,调用hilink_ota_rpt_prg进行上报
|
||||
* cb返回0时hilink sdk被拉起后会立即上报进度0
|
||||
* 产品根据自身升级情况判断是否需要注册cb,如不注册则默认hilink sdk被拉起后会立即上报进度0
|
||||
*/
|
||||
void HILINK_PowerOnRptUpgProgress(RptUpgProgressFlagCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* HILINK_OPEN_OTA_BRIDGE_ADAPTER_H */
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
|
||||
* Description: OTA适配实现 (需设备厂商实现)
|
||||
*/
|
||||
#include "hilink_open_ota_adapter.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#define DOWNLOAD_PATITION_ADDR 0x253000 //68+2048+300KB
|
||||
#define DOWNLOAD_PATITION_LEN 0x187000 //1536KB
|
||||
static unsigned int write_length = 0;
|
||||
#define HILINK_OK 0
|
||||
#define HILINK_ERROR -1
|
||||
|
||||
/*
|
||||
* Flash初始化
|
||||
* 返回值是true时,表示初始化正常
|
||||
* 返回值是false时,表示初始化异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashInit(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashInit start\r\n");
|
||||
IoTFlashInit();
|
||||
write_length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 判断需要升级的分区
|
||||
* 返回值是UPGRADE_FW_BIN1时,表示升级固件到分区1
|
||||
* 返回值是UPGRADE_FW_BIN2时,表示升级固件到分区2
|
||||
*/
|
||||
unsigned int HILINK_OtaAdapterGetUpdateIndex(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterGetUpdateIndex start\r\n");
|
||||
return UPGRADE_FW_BIN1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 擦除需要升级的分区
|
||||
* size表示需要擦除的分区大小
|
||||
* 返回值是ILINK_OK时,表示擦除成功
|
||||
* 返回值是HILINK_ERROR时,表示擦除失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashErase(unsigned int size)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashErase start size=%d\r\n",size);
|
||||
return IoTFlashErase(DOWNLOAD_PATITION_ADDR,DOWNLOAD_PATITION_LEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* 升级数据写入升级的分区
|
||||
* buf表示待写入数据
|
||||
* bufLen表示待写入数据的长度
|
||||
* 返回值是HILINK_OK时,表示写入成功
|
||||
* 返回值是HILINK_ERROR时,表示写入失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int bufLen)
|
||||
{
|
||||
//printf("HILINK_OtaAdapterFlashWrite start\r\n");
|
||||
#if 1
|
||||
int ret;
|
||||
if (bufLen == 0)
|
||||
{
|
||||
return HILINK_OK;
|
||||
}
|
||||
if (buf == NULL)
|
||||
{
|
||||
return HILINK_ERROR;
|
||||
}
|
||||
|
||||
ret = IoTFlashWrite(DOWNLOAD_PATITION_ADDR + write_length, bufLen, buf, 0);
|
||||
|
||||
write_length += bufLen;
|
||||
if(ret == 0)
|
||||
return HILINK_OK;
|
||||
else
|
||||
return HILINK_ERROR;
|
||||
#else
|
||||
return HILINK_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 读取升级分区数据
|
||||
* offset表示读写偏移
|
||||
* buf表示输出数据的内存地址
|
||||
* bufLen表示输出数据的内存长度
|
||||
* 返回值是HILINK_OK时,表示读取成功
|
||||
* 返回值是HILINK_ERROR时,表示读取失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int bufLen)
|
||||
{
|
||||
//printf("HILINK_OtaAdapterFlashRead start\r\n");
|
||||
#if 1
|
||||
int ret;
|
||||
if ( (buf == NULL) || (bufLen == 0))
|
||||
{
|
||||
return HILINK_ERROR;
|
||||
}
|
||||
ret = IoTFlashRead(DOWNLOAD_PATITION_ADDR + offset, bufLen, buf);
|
||||
|
||||
if(ret == 0)
|
||||
return HILINK_OK;
|
||||
else
|
||||
return HILINK_ERROR;
|
||||
#else
|
||||
return HILINK_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* 分区升级结束
|
||||
* 返回值是true时,表示结束正常
|
||||
* 返回值是false时,表示结束异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashFinish(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashFinish start\r\n");
|
||||
IoTFlashDeinit();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 获取升级区间最大长度 */
|
||||
unsigned int HILINK_OtaAdapterFlashMaxSize(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashMaxSize start\r\n");
|
||||
|
||||
return DOWNLOAD_PATITION_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据标志重启模组
|
||||
* flag表示重启标志
|
||||
* 当flag是RESTART_FLAG_NOW时,表示只有MCU升级时立即重启
|
||||
* 当flag是RESTART_FLAG_LATER时,表示有模组时切换分区后再重启
|
||||
*/
|
||||
void HILINK_OtaAdapterRestart(int flag)
|
||||
{
|
||||
printf("HILINK_OtaAdapterRestart start\r\n");
|
||||
reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 开始模组升级
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将开始启动升级流程
|
||||
* 返回值是RETURN_ERROR时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:在手动场景场景下,HiLink SDK在接收到用户发出的升级指令后,将直接调用此接口;
|
||||
* 在自动升级场景下,当HiLink SDK在调用HilinkGetRebootFlag接口返回值是MODULE_CAN_REBOOT时,HiLink SDK将调用此接口。
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_OtaStartProcess(int type)
|
||||
{
|
||||
printf("HILINK_OtaStartProcess start type =%d\r\n",type);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 模组升级结束
|
||||
* status表示升级结果
|
||||
* 当status是100时,表示升级成功
|
||||
* 当status不是100时,表示升级失败
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将置升级标志或切换运行区标志
|
||||
* 返回值不是RETURN_OK时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:HiLink SDK在将固件写入到OTA升级区后,且完整性校验通过后,将调用厂商适配的此接口;
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等;升级类型是否为自动升级可参考接口HilinkOtaStartProcess的参数type的描述。
|
||||
*/
|
||||
int HILINK_OtaEndProcess(int status)
|
||||
{
|
||||
printf("HILINK_OtaEndProcess start status=%d\r\n",status);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断模组是否能立即升级并重启
|
||||
* 返回值是MODULE_CAN_REBOOT时,表示模组可以立即升级并重启,HiLink SDK将开始自动升级流程。
|
||||
* 返回值是MODULE_CANNOT_REBOOT时,表示模组不能立即升级并重启,HiLink SDK将不进行本次自动升级流程。
|
||||
* 注意:在用户同意设备可以自动升级的情况下,HiLink SDK调用此接口获取设备当前业务状态下,模组是否可以立即升级并重启的标志。
|
||||
* 只有当设备处于业务空闲状态时,接口才可以返回MODULE_CAN_REBOOT。
|
||||
* 当设备处于业务非空闲状态时,接口返回MODULE_CANNOT_REBOOT。
|
||||
*/
|
||||
int HILINK_GetRebootFlag(void)
|
||||
{
|
||||
printf("HILINK_GetRebootFlag start\r\n");
|
||||
return MODULE_CAN_REBOOT;
|
||||
}
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本升级
|
||||
* 检测到的版本,sdk将通过cb回调函数触发升级
|
||||
*/
|
||||
void HILINK_TrigOtaSelfUpdate(TrigSelfUpdateCb cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
|
||||
* Description: 外挂MCU升级适配实现 (需设备厂商实现)
|
||||
*/
|
||||
|
||||
#include "hilink_open_ota_mcu_adapter.h"
|
||||
|
||||
/*
|
||||
* 获取MCU当前版本
|
||||
* version表示版本字符串
|
||||
* inLen表示输入字符串长度
|
||||
* outLen表示输出字符串长度
|
||||
* 返回值是RETURN_OK时,表示获取成功
|
||||
* 返回值是RETURN_ERROR_NO_MCU时,表示没有MCU
|
||||
* 返回值是RETURN_ERROR时,表示获取失败
|
||||
* 返回值是RETURN_MCU_NO_NEED_OTA时,表示不需要MCU升级
|
||||
* 注意:如果获取不到MCU的版本,则不对MCU进行升级。
|
||||
* 建议厂商在MCU正常启动后,或升级启动后,就将MCU的版本号传递给模组,确保模组可以获取到MCU的版本。
|
||||
*/
|
||||
int HILINK_GetMcuVersion(char *version, unsigned int inLen, unsigned int *outLen)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知MCU固件传输的状态
|
||||
* flag表示升级流程标志
|
||||
* 当flag是START_SEND_DATA时,表示通知模组即将开始发送MCU固件数据包
|
||||
* 当flag是STOP_SEND_DATA时,表示通知模组完整的MCU固件包已发送完成
|
||||
* 当flag是SEND_DATA_ERROR时,表示通知模组本次MCU固件升级异常终止
|
||||
* len表示MCU固件包的大小
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,表示处理失败,HiLink SDK将终止本次MCU升级流程
|
||||
* 注意:当flag是STOP_SEND_DATA时,此接口需返回MCU侧固件升级的结果;当flag是其它值时,需返回接口接收到此消息后的处理结果。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_NotifyOtaStatus(int flag, unsigned int len, unsigned int type)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知厂商发送MCU固件文件数据
|
||||
* data表示发送的数据
|
||||
* len表示发送的数据的长度
|
||||
* offset表示发送的数据起始位置相对于完整固件包的偏移量
|
||||
* 此接口需要返回MCU接收这部分数据的处理结果
|
||||
* 返回值是RETURN_OK时,模组将通知的数据正确发送给MCU,且MCU正确处理发送的数据,HiLink SDK将继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,模组或MCU未能正常处理通知的MCU的固件文件数据,HiLink SDK将终止本次MCU固件升级流程
|
||||
*/
|
||||
int HILINK_NotifyOtaData(const unsigned char *data, unsigned int len, unsigned int offset)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#import("//applications/iot_solution/device.gni")
|
||||
|
||||
oem_common_deps = [
|
||||
# "//build/lite/config/component/cJSON:cjson_shared",
|
||||
# "//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
|
||||
config("oem_common_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/cJSON/",
|
||||
"//third_party/mbedtls/include",
|
||||
"//kernel/liteos_m/components/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
# "//device/asr/asr582x/drivers/kv/include/",
|
||||
]
|
||||
defines = []
|
||||
}
|
||||
|
||||
static_library("oem_auth_result_storage") {
|
||||
sources = [ "src/oem_auth_result_storage.c" ]
|
||||
configs += [ ":oem_common_config" ]
|
||||
deps = oem_common_deps
|
||||
}
|
||||
|
||||
static_library("oem_auth_config") {
|
||||
sources = [ "src/oem_auth_config.c" ]
|
||||
configs += [ ":oem_common_config" ]
|
||||
deps = oem_common_deps
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: interface file for kitframework client
|
||||
* Author: yangzuxun
|
||||
* Create: 2020-07-20
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_KIT_FRAMEWORK_CLIENT_H
|
||||
#define HOS_LITE_KIT_FRAMEWORK_CLIENT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
// request auth result
|
||||
#define ERR_OK 0
|
||||
#define SERVICE_UNAVAILABLE (-1)
|
||||
#define INVALID_PARAM (-2)
|
||||
|
||||
#define PASS 0
|
||||
#define FAIL (-1)
|
||||
#define UNKNOWN (-2)
|
||||
|
||||
// define authentication control policy
|
||||
#define POLICY_ALERT (0x1 << 0) // 警告,kit自行决定
|
||||
#define POLICY_DENY (0x1 << 1) // 拒绝
|
||||
#define POLICY_PASS (0x1 << 2) // 放通
|
||||
#define POLICY_INVISBLE (0x1 << 3) // 设备不可见
|
||||
|
||||
// kit id
|
||||
#define DV_KIT "DvKit"
|
||||
#define CAST_KIT "CastKit"
|
||||
#define HI_LINK "HiLinkKit"
|
||||
#define HI_CAR "HiCarKit"
|
||||
#define SHARE "ShareKit"
|
||||
#define MEET_TIME "MeetTimeKit"
|
||||
#define ONE_HOP "OneHopKit"
|
||||
#define ONE_TAG "OneTagKit"
|
||||
|
||||
// CheckModuleValid return value
|
||||
#define RET_OK 1
|
||||
#define RET_FALSE 0
|
||||
#define RET_INVALID (-1)
|
||||
|
||||
typedef enum {
|
||||
TYPE_AA, // hap or static form
|
||||
TYPE_DEBUG, // debug version
|
||||
TYPE_BDREPORT, // big data report module
|
||||
TYPE_D2D, // D2D module
|
||||
TYPE_D2C, // D2C module
|
||||
} CheckType;
|
||||
|
||||
typedef struct AuthStatus AuthStatus;
|
||||
typedef void (*IAuthResultCallback)(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to initial the authtication client and connect to the
|
||||
* kit server, and return the connect status. The function must be called before
|
||||
* RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback).
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
* @return error_code: REQ_OK or SERVICE_UNAVAILABLE or INVALID_PARAM
|
||||
*/
|
||||
int32_t CreateKitFrameworkClient(const char* kitId);
|
||||
|
||||
/**
|
||||
* @brief The function is used to trigger device auth, and return the auth result.
|
||||
* The caller can only call the function without calling CreateKitFrameworkClient(const char* kitId) before.
|
||||
* @param networkId: the name defined in soft-bus, NULL for local device.
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
* @param callback: the Auth check result callback.
|
||||
* @return error_code: REQ_OK or SERVICE_UNAVAILABLE or INVALID_PARAM
|
||||
*/
|
||||
int32_t RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback);
|
||||
|
||||
/**
|
||||
* @brief The function is used to close the connection of kit server and release the client.
|
||||
* The function must be called after
|
||||
* RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback).
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
*/
|
||||
void CloseKitFrameworkClient(const char* kitId);
|
||||
|
||||
/**
|
||||
* @brief The function is used to check the type whether exists or not
|
||||
* @param type: the check module type.
|
||||
* @return error_code: RET_OK or RET_FALSE or RET_INVALID
|
||||
*/
|
||||
int32_t CheckModuleValid(CheckType type);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get device auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of device.
|
||||
*/
|
||||
int32_t GetDeviceStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get system auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of system.
|
||||
*/
|
||||
int32_t GetSystemStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get kit auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of kit.
|
||||
*/
|
||||
int32_t GetKitStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get kit auth policy;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth policy of kit.
|
||||
*/
|
||||
int32_t GetAuthPolicy(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get ticket;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return NULL or ticket , max size is 256.
|
||||
*/
|
||||
const char* GetTicket(const AuthStatus* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: headfile of oem_auth_config
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_OEM_AUTH_CONFIG_H
|
||||
#define HOS_LITE_OEM_AUTH_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "mbedtls/x509_crt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief read authentication's server info from device which implemented by OEM.
|
||||
* format: server1:port1;server2:port2; ...
|
||||
* @param port: pointer of server info's buffer.
|
||||
* @param len: length of server info's buffer, max value is 256.
|
||||
* The max length for signal NV srtuct is 252 Bytes, so please be careful if the server info is save as NV.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadAuthServerInfo(char* buff, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief load kit's id and verison information from device which implemented by OEM.
|
||||
* @return char* not NULL means load succeed, NULL is means OEM haven't set kit infos or no others kit to authenticate
|
||||
* example : NULL means no others kit
|
||||
* "{\"KitInfos\":[]}" means no others kit
|
||||
* "{\"KitInfos\":[{\"HiLinkKit\":\"1.0.0\"},{\"DvKit\":\"1.0.1\"}]}" means with HiLink and DvKit
|
||||
*/
|
||||
char* OEMLoadKitInfos(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HOS_LITE_OEM_AUTH_CONFIG_H */
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: headfile of oem_auth_result_storage
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
#ifndef HOS_LITE_OEM_AUTH_RESULT_STORAGE_H
|
||||
#define HOS_LITE_OEM_AUTH_RESULT_STORAGE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief check whether the temperature of the device's flash chip is over limit or not.
|
||||
* @return true is over limit.
|
||||
*/
|
||||
bool OEMIsOverTemperatureLimit(void);
|
||||
|
||||
/**
|
||||
* @brief check reset flag is exist or not which implemented by OEM.
|
||||
* @return true is reset flag existed, false is not.
|
||||
*/
|
||||
bool OEMIsResetFlagExist(void);
|
||||
|
||||
/**
|
||||
* @brief create reset flag in device which implemented by OEM.
|
||||
* @return 0 is create succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMCreateResetFlag(void);
|
||||
|
||||
/**
|
||||
* @brief delete reset flag in device which implemented by OEM.
|
||||
* @return 0 is create succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteResetFlag(void);
|
||||
|
||||
/**
|
||||
* @brief check auth status file is exist or not which implemented by OEM.
|
||||
* @return true is auth status file existed, false is not.
|
||||
*/
|
||||
bool OEMIsAuthStatusExist(void);
|
||||
|
||||
/**
|
||||
* @brief write auth status to device which implemented by OEM.
|
||||
* @param data: pointer of data which to be written.
|
||||
* @param len: length of data which to be written.
|
||||
* @return 0 is written succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMWriteAuthStatus(const char* data, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief read auth status from device which implemented by OEM.
|
||||
* @param buffer: pointer of auth status's buffer.
|
||||
* @param bufferLen: length of auth status's buffer.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadAuthStatus(char* buffer, uint32_t bufferLen);
|
||||
|
||||
/**
|
||||
* @brief delete auth status file from device which implemented by OEM.
|
||||
* @return 0 is delete succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteAuthStatus(void);
|
||||
|
||||
/**
|
||||
* @brief get auth status's content size from device which implemented by OEM.
|
||||
* @param len: pointer of auth status's content size.
|
||||
* @return 0 is succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMGetAuthStatusFileSize(uint32_t* len);
|
||||
|
||||
/**
|
||||
* @brief check ticket file is exist or not which implemented by OEM.
|
||||
* @return true is ticket file existed, false is not.
|
||||
*/
|
||||
bool OEMIsTicketExist(void);
|
||||
|
||||
/**
|
||||
* @brief write ticket to device which implemented by OEM.
|
||||
* @param data: pointer of data which to be written.
|
||||
* @param len: length of data which to be written.
|
||||
* @return 0 is written succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMWriteTicket(const char* data, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief read ticket from device which implemented by OEM.
|
||||
* @param buffer: pointer of ticket's buffer.
|
||||
* @param bufferLen: length of ticket's buffer.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadTicket(char* buffer, uint32_t bufferLen);
|
||||
|
||||
/**
|
||||
* @brief delete ticket file from device which implemented by OEM.
|
||||
* @return 0 is delete succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteTicket(void);
|
||||
|
||||
/**
|
||||
* @brief get ticket's content size from device which implemented by OEM.
|
||||
* @param len: pointer of ticket's content size.
|
||||
* @return 0 is succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMGetTicketFileSize(uint32_t* len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HOS_LITE_OEM_AUTH_RESULT_STORAGE_H */
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: implement of oem_auth_config
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#include "oem_auth_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#define HCS_HILINKKIT
|
||||
#define KIT_ID_LEN 40
|
||||
|
||||
typedef const char *(*KitGetVerFunc)();
|
||||
|
||||
typedef struct KitGetVerInfo
|
||||
{
|
||||
char kitId[KIT_ID_LEN + 1];
|
||||
KitGetVerFunc kitGetVerFunc;
|
||||
} KitGetVerInfo;
|
||||
|
||||
#ifdef HCS_DVKIT
|
||||
extern const char *DvKit_GetVersion();
|
||||
#endif
|
||||
|
||||
#ifdef HCS_HILINKKIT
|
||||
// extern const char* HiLinkKit_GetVersion();
|
||||
const char *HiLinkKit_GetVersion()
|
||||
{
|
||||
return "1.0.0";
|
||||
}
|
||||
#endif
|
||||
|
||||
KitGetVerInfo g_kitGetVerInfo[] = {
|
||||
#ifdef HCS_DVKIT
|
||||
{"DvKit", DvKit_GetVersion},
|
||||
#endif
|
||||
#ifdef HCS_HILINKKIT
|
||||
{"HiLinkKit", HiLinkKit_GetVersion},
|
||||
#endif
|
||||
{0, NULL}};
|
||||
#define TOTAL_TIMEOUT 10000
|
||||
#define KIT_INFO_JSON_KEY "KitInfos"
|
||||
uint32_t OEMGetTotalTimeout()
|
||||
{
|
||||
return TOTAL_TIMEOUT;
|
||||
}
|
||||
|
||||
int32_t OEMReadAuthServerInfo(char *buff, uint32_t len)
|
||||
{
|
||||
if (buff == NULL || len == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *OEMLoadKitInfos(void)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
if (root == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
cJSON *infos = cJSON_CreateArray();
|
||||
if (infos == NULL)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint32_t kitCount = sizeof(g_kitGetVerInfo) / sizeof(KitGetVerInfo);
|
||||
for (uint32_t i = 0; i < kitCount; i++)
|
||||
{
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
if (obj == NULL)
|
||||
{
|
||||
printf("OEM Adapter: Create json object failed\n");
|
||||
continue;
|
||||
}
|
||||
const char *key = g_kitGetVerInfo[i].kitId;
|
||||
KitGetVerFunc kitGetVerFunc = g_kitGetVerInfo[i].kitGetVerFunc;
|
||||
if (key == NULL || strlen(key) == 0 || kitGetVerFunc == NULL)
|
||||
{
|
||||
cJSON_Delete(obj);
|
||||
continue;
|
||||
}
|
||||
const char *value = (kitGetVerFunc)();
|
||||
if (value == NULL || strlen(value) == 0 || cJSON_AddStringToObject(obj, key, value) == NULL)
|
||||
{
|
||||
printf("OEM Adapter: Add kit info %s to json object failed\n", key);
|
||||
cJSON_Delete(obj);
|
||||
continue;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(infos, obj))
|
||||
{
|
||||
cJSON_Delete(obj);
|
||||
printf("OEM Adapter: Add kit info %s to json array failed\n", key);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cJSON_AddItemToObject(root, KIT_INFO_JSON_KEY, infos))
|
||||
{
|
||||
printf("OEM Adapter: Add kit infos to json object failed\n");
|
||||
cJSON_Delete(infos);
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
char *result = cJSON_PrintUnformatted(root);
|
||||
cJSON_Delete(root);
|
||||
return result;
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: implement of oem_auth_result_storage
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#include "oem_auth_result_storage.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "utils_file.h"
|
||||
|
||||
#define RESET_FILE_NAME "auth_reset"
|
||||
#define TICKET_FILE_NAME "auth_ticket"
|
||||
#define AUTH_STATS_FILE_NAME "auth_authstats"
|
||||
|
||||
#define WRITE_FLASH_MAX_TEMPERATURE 80
|
||||
static const uint32_t MAX_FILE_BYTES_LIMIT = 5120;
|
||||
|
||||
bool OEMIsOverTemperatureLimit(void)//???¨¨?D?¦Ì?D??
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsFileExist(const char* path)
|
||||
{
|
||||
printf("IsFileExist start path=%s\r\n",path);
|
||||
if(path == NULL)
|
||||
return false;
|
||||
int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
(void)UtilsFileClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t CreateFile(const char* path)
|
||||
{
|
||||
printf("CreateFile start path=%s\r\n",path);
|
||||
if(path == NULL)
|
||||
return false;
|
||||
int32_t fd = UtilsFileOpen(path, O_CREAT_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
(void)UtilsFileClose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int32_t WriteFile(const char* path,const char* data,uint32_t datalen,int flag)
|
||||
{
|
||||
printf("WriteFile start path=%s\r\n",path);
|
||||
if(path == NULL || data == NULL || datalen == 0)
|
||||
{
|
||||
printf("WriteFile data invalid\r\n");
|
||||
return -1;
|
||||
}
|
||||
if(datalen > MAX_FILE_BYTES_LIMIT)
|
||||
{
|
||||
printf("WriteFile data over limit\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(OEMIsOverTemperatureLimit())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int32_t fd = UtilsFileOpen(path, flag, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("WriteFile open failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if(UtilsFileWrite(fd, data, datalen) != datalen)
|
||||
{
|
||||
printf("WriteFile write failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)UtilsFileClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadFile(const char* path,const char* buffer,uint32_t bufferlen)
|
||||
{
|
||||
printf("ReadFile start path=%s\r\n",path);
|
||||
if(path == NULL || buffer == NULL || bufferlen == 0)
|
||||
{
|
||||
printf("ReadFile data invalid\r\n");
|
||||
return -1;
|
||||
}
|
||||
if(!IsFileExist(path))
|
||||
{
|
||||
printf("ReadFile file not exsit\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t filesize = 0;
|
||||
if(UtilsFileStat(path,&filesize) != 0)
|
||||
{
|
||||
printf("ReadFile stat file failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(filesize > bufferlen)
|
||||
{
|
||||
printf("ReadFile read data over buffer lenth\r\n");
|
||||
return -1;
|
||||
}
|
||||
int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("ReadFile open failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if(UtilsFileRead(fd, buffer, filesize) != filesize)
|
||||
{
|
||||
printf("ReadFile read data failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)UtilsFileClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t DeleteFile(const char* path)
|
||||
{
|
||||
UtilsFileDelete(path);
|
||||
}
|
||||
|
||||
bool OEMIsResetFlagExist(void)
|
||||
{
|
||||
return IsFileExist(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMCreateResetFlag(void)
|
||||
{
|
||||
return CreateFile(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteResetFlag(void)
|
||||
{
|
||||
return DeleteFile(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
bool OEMIsAuthStatusExist(void)
|
||||
{
|
||||
return IsFileExist(AUTH_STATS_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMWriteAuthStatus(const char* data, uint32_t len)
|
||||
{
|
||||
if(data == NULL || len == 0)
|
||||
return -1;
|
||||
|
||||
return WriteFile(AUTH_STATS_FILE_NAME,data,len,O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS);
|
||||
}
|
||||
|
||||
int32_t OEMReadAuthStatus(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
if(buffer == NULL || bufferLen == 0)
|
||||
return -1;
|
||||
|
||||
return ReadFile(AUTH_STATS_FILE_NAME,buffer,bufferLen);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteAuthStatus(void)
|
||||
{
|
||||
return DeleteFile(AUTH_STATS_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMGetAuthStatusFileSize(uint32_t* len)
|
||||
{
|
||||
printf("OEMGetAuthStatusFileSize len=%p\r\n",len);
|
||||
if(len == NULL)
|
||||
return -1;
|
||||
|
||||
return UtilsFileStat(AUTH_STATS_FILE_NAME,len);
|
||||
}
|
||||
|
||||
bool OEMIsTicketExist(void)
|
||||
{
|
||||
return IsFileExist(TICKET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMWriteTicket(const char* data, uint32_t len)
|
||||
{
|
||||
printf("OEMWriteTicket data=%s -- len=%d\r\n",data,len);
|
||||
if(data == NULL || len == 0)
|
||||
return -1;
|
||||
|
||||
return WriteFile(TICKET_FILE_NAME,data,len,O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS);
|
||||
}
|
||||
|
||||
int32_t OEMReadTicket(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
printf("OEMReadTicket buffer=%s -- bufferLen=%d\r\n",buffer,bufferLen);
|
||||
if(buffer == NULL || bufferLen == 0)
|
||||
return -1;
|
||||
|
||||
return ReadFile(TICKET_FILE_NAME,buffer,bufferLen);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteTicket(void)
|
||||
{
|
||||
return DeleteFile(TICKET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMGetTicketFileSize(uint32_t* len)
|
||||
{
|
||||
return UtilsFileStat(TICKET_FILE_NAME,len);
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
static_library("hal_sysparam") {
|
||||
sources = [ "hal_sys_param.c" ]
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
defines = [
|
||||
"INCREMENTAL_VERSION=\"${ohos_version}\"",
|
||||
"BUILD_TYPE=\"${ohos_build_type}\"",
|
||||
"BUILD_USER=\"${ohos_build_user}\"",
|
||||
"BUILD_TIME=\"${ohos_build_time}\"",
|
||||
"BUILD_HOST=\"${ohos_build_host}\"",
|
||||
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
|
||||
]
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
#include "hal_sys_param.h"
|
||||
|
||||
|
||||
#define PRD_Lamp_2HSB 1 /* DALEN product wifi+BLE +KIT */
|
||||
#define PRD_Lamp_2IES 2 /* DALEN product wifi+BLE +KIT */
|
||||
|
||||
|
||||
#define USING_PRODUCT_ID PRD_Lamp_2HSB
|
||||
|
||||
#if(USING_PRODUCT_ID == PRD_Lamp_2HSB)
|
||||
static const char OHOS_DEVICE_TYPE[] = {"Table Lamp"};
|
||||
static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
|
||||
static const char OHOS_MANUFACTURE[] = {"BEKEN"};
|
||||
static const char OHOS_BRAND[] = {"BEKEN"};
|
||||
static const char OHOS_MARKET_NAME[] = {"BK7231M-LIGHT"};
|
||||
static const char OHOS_PRODUCT_SERIES[] = {"light"};
|
||||
static const char OHOS_PRODUCT_MODEL[] = {"light-01"};
|
||||
static const char OHOS_SOFTWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"wifi:true,ble:true"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const char OHOS_ABI_LIST[] = {"riscv-liteos"};
|
||||
//static const char OHOS_SERIAL[] = {"C86000000001"};
|
||||
char OHOS_SERIAL[16] = {0};
|
||||
#elif(USING_PRODUCT_ID == PRD_Lamp_2IES)
|
||||
static const char OHOS_DEVICE_TYPE[] = {"Table Lamp"};
|
||||
static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
|
||||
static const char OHOS_MANUFACTURE[] = {"BEKEN"};
|
||||
static const char OHOS_BRAND[] = {"BEKEN"};
|
||||
static const char OHOS_MARKET_NAME[] = {"BK7235-LIGHT"};
|
||||
static const char OHOS_PRODUCT_SERIES[] = {"bk7235"};
|
||||
static const char OHOS_PRODUCT_MODEL[] = {"bk7235-002"};
|
||||
static const char OHOS_SOFTWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"wifi:true,ble:true"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const char OHOS_ABI_LIST[] = {"riscv-liteos"};
|
||||
|
||||
//static const char OHOS_SERIAL[] = {"123456789"};
|
||||
char OHOS_SERIAL[16] = {0};
|
||||
|
||||
#endif
|
||||
static const int OHOS_FIRST_API_VERSION = 1;
|
||||
|
||||
const char* HalGetDeviceType(void)
|
||||
{
|
||||
return OHOS_DEVICE_TYPE;
|
||||
}
|
||||
|
||||
const char* HalGetManufacture(void)
|
||||
{
|
||||
return OHOS_MANUFACTURE;
|
||||
}
|
||||
|
||||
const char* HalGetBrand(void)
|
||||
{
|
||||
return OHOS_BRAND;
|
||||
}
|
||||
|
||||
const char* HalGetMarketName(void)
|
||||
{
|
||||
return OHOS_MARKET_NAME;
|
||||
}
|
||||
|
||||
const char* HalGetProductSeries(void)
|
||||
{
|
||||
return OHOS_PRODUCT_SERIES;
|
||||
}
|
||||
|
||||
const char* HalGetProductModel(void)
|
||||
{
|
||||
return OHOS_PRODUCT_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetSoftwareModel(void)
|
||||
{
|
||||
return OHOS_SOFTWARE_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetHardwareModel(void)
|
||||
{
|
||||
return OHOS_HARDWARE_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetHardwareProfile(void)
|
||||
{
|
||||
return OHOS_HARDWARE_PROFILE;
|
||||
}
|
||||
char make_ohos_serial[16] = {0};
|
||||
#define in_range(c, lo, up) ((unsigned char)c >= lo && (unsigned char)c <= up)
|
||||
#define islower(c) in_range(c, 'a', 'z')
|
||||
#include "string.h"
|
||||
const char* HalGetSerial(void)
|
||||
{
|
||||
#if 1
|
||||
typedef int bk_err_t; /**< Return error code */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char mac_type_t;
|
||||
uint8_t mac_read[6];
|
||||
|
||||
extern bk_err_t bk_get_mac(uint8_t *mac, mac_type_t type);
|
||||
bk_get_mac(mac_read,0);
|
||||
os_snprintf(&make_ohos_serial[0],sizeof(make_ohos_serial),"%02x%02x%02x%02x%02x%02x",mac_read[0],mac_read[1],mac_read[2],mac_read[3],mac_read[4],mac_read[5]);
|
||||
|
||||
for(int i = 0; i<sizeof(make_ohos_serial);i++)
|
||||
{
|
||||
if(islower(make_ohos_serial[i]))
|
||||
make_ohos_serial[i] +='A' - 'a';
|
||||
}
|
||||
memcpy(OHOS_SERIAL,make_ohos_serial,strlen(make_ohos_serial)+1);
|
||||
#endif
|
||||
printf("OHOS_SERIAL=%s\r\n",OHOS_SERIAL);
|
||||
return OHOS_SERIAL;
|
||||
}
|
||||
|
||||
const char* HalGetBootloaderVersion(void)
|
||||
{
|
||||
return OHOS_BOOTLOADER_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetAbiList(void)
|
||||
{
|
||||
return OHOS_ABI_LIST;
|
||||
}
|
||||
|
||||
const char* HalGetDisplayVersion(void)
|
||||
{
|
||||
return OHOS_DISPLAY_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetIncrementalVersion(void)
|
||||
{
|
||||
return INCREMENTAL_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetBuildType(void)
|
||||
{
|
||||
return BUILD_TYPE;
|
||||
}
|
||||
|
||||
const char* HalGetBuildUser(void)
|
||||
{
|
||||
return BUILD_USER;
|
||||
}
|
||||
|
||||
const char* HalGetBuildHost(void)
|
||||
{
|
||||
return BUILD_HOST;
|
||||
}
|
||||
|
||||
const char* HalGetBuildTime(void)
|
||||
{
|
||||
return BUILD_TIME;
|
||||
}
|
||||
|
||||
int HalGetFirstApiVersion(void)
|
||||
{
|
||||
return OHOS_FIRST_API_VERSION;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
const.build.characteristics=****
|
||||
|
||||
const.product.manufacturer=****
|
||||
|
||||
const.product.brand=****
|
||||
|
||||
const.product.name=****
|
||||
|
||||
const.build.product=****
|
||||
|
||||
const.product.model=****
|
||||
|
||||
const.software.model=****
|
||||
|
||||
const.product.hardwareversion=****
|
||||
|
||||
const.product.hardwareprofile="aout:true,display:true"
|
||||
|
||||
const.ohos.serial=1234567890
|
||||
|
||||
const.product.bootloader.version=bootloader
|
||||
|
||||
const.product.cpu.abilist=****
|
||||
|
||||
const.product.software.version="OpenHarmony 1.0.1"
|
||||
|
||||
const.product.firstapiversion=1
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
# Copyright (c) 2020 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.
|
||||
import("${board_adapter_dir}/hals/sdk_dir.gni")
|
||||
|
||||
static_library("hal_token_static") {
|
||||
sources = [ "hal_token.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
"${beken_sdk_dir}/include",
|
||||
"${beken_sdk_dir}/include/arch/compiler",
|
||||
"${beken_sdk_dir}/components/bk_cli/include",
|
||||
"${beken_sdk_dir}/components/bk_cli/include/bk_private",
|
||||
"//utils/native/lite/hals/file",
|
||||
"//applications/iot_solution/thing_model/WiFi",
|
||||
|
||||
]
|
||||
include_dirs += bk_hal_include_dirs
|
||||
|
||||
deps = []
|
||||
}
|
||||
Executable
+352
@@ -0,0 +1,352 @@
|
||||
#include "hal_token.h"
|
||||
#include "bk_cli.h"
|
||||
#include "ohos_errno.h"
|
||||
#include "ohos_types.h"
|
||||
#include "utils_file.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "hal_file.h"
|
||||
#include <securec.h>
|
||||
#include "iot_device.h"
|
||||
|
||||
|
||||
#define TokenPathA "/usrdata/hilink/tokenA.cfg"
|
||||
#define TokenPathB "/usrdata/hilink/tokenB.cfg"
|
||||
#define TOKEN_SIZE 151
|
||||
#define BITS_PER_BYTE 8
|
||||
// 4 Bytes for token flag
|
||||
// if token's both area are available, when read token, always return area which flag is bigger;
|
||||
// and recover area which flag is small while write token.
|
||||
#define TOKEN_FLAG_SIZE 4
|
||||
#define TOKEN_WITH_FLAG_SIZE (TOKEN_SIZE + TOKEN_FLAG_SIZE)
|
||||
|
||||
#define tokenstring "Y1DjGH2dzole/ZXcWPSBj1aysCNBqJ633C2AJPG0tHliEktcHys3WW15F/fSLEcP,kf+TmQyFh43H7loKz80Zz8Avog6xA+u3hM47Qcm2UicQ5GrHNRNBbnhxxYm8Q7Ve,n0yQTslNQFsnvrM3,0000"
|
||||
|
||||
static uint32_t GetTokenFlag(const char tokenWithFlag[])
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for (uint32_t i = 0; i < TOKEN_FLAG_SIZE; i++) {
|
||||
result |= ((uint8_t)tokenWithFlag[TOKEN_SIZE + i]) << ((TOKEN_FLAG_SIZE - 1 - i) * BITS_PER_BYTE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void SetTokenFlag(uint8_t flag[], uint32_t value)
|
||||
{
|
||||
for (uint32_t i = 0; i < TOKEN_FLAG_SIZE; i++) {
|
||||
flag[i] = (value >> (BITS_PER_BYTE * (TOKEN_FLAG_SIZE - 1 - i))) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int OEMReadToken(char *token, unsigned int len)
|
||||
{
|
||||
int tokenAfd,tokenBfd;
|
||||
int tokenReadLen;
|
||||
(void) tokenReadLen;
|
||||
tokenAfd = HalFileOpen(TokenPathA , O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
if((tokenAfd < 0)&&(tokenBfd < 0)){
|
||||
memcpy((char *)token, (char *)tokenstring, len);
|
||||
return EC_SUCCESS;//-2;
|
||||
|
||||
}else if((tokenAfd >= 0)&&(tokenBfd < 0)){
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenReadLen = HalFileRead(tokenAfd,token,len);
|
||||
HalFileClose(tokenAfd);
|
||||
return EC_SUCCESS;
|
||||
|
||||
}else if((tokenAfd < 0)&&(tokenBfd >= 0)){
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenReadLen = HalFileRead(tokenBfd,token,len);
|
||||
HalFileClose(tokenBfd);
|
||||
return EC_SUCCESS;
|
||||
|
||||
}else if((tokenAfd >= 0)&&(tokenBfd >= 0)){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenReadLen = HalFileRead(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
tokenReadLen = HalFileRead(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
uint32_t flagA = GetTokenFlag(tokenA_withFlag);
|
||||
uint32_t flagB = GetTokenFlag(tokenB_withFlag);
|
||||
if(flagA >= flagB){
|
||||
(void)memcpy_s(token, len, tokenA_withFlag, len);
|
||||
}else{
|
||||
(void)memcpy_s(token, len, tokenB_withFlag, len);
|
||||
}
|
||||
free(tokenA_withFlag);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
HalFileClose(tokenBfd);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int OEMWriteToken(const char *token, unsigned int len)
|
||||
{
|
||||
int tokenAfd,tokenBfd;
|
||||
int tokenAfileSize,tokenBfileSize;
|
||||
int tokenWriteLen;
|
||||
(void )tokenWriteLen;
|
||||
uint32_t flagA,flagB;
|
||||
|
||||
tokenAfileSize = FileSize(TokenPathA );
|
||||
tokenBfileSize = FileSize(TokenPathB);
|
||||
|
||||
if((tokenAfileSize <= 0)&&(tokenBfileSize <= 0)){
|
||||
//no A,no B. creat A
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_CREAT_FS|O_RDWR_FS, 0);
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],1);
|
||||
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenA_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
}
|
||||
|
||||
}else if((tokenAfileSize > 0)&&(tokenBfileSize <= 0)){
|
||||
//only A. creat B
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_CREAT_FS|O_RDWR_FS, 0);
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagA = GetTokenFlag(tokenA_withFlag);
|
||||
free(tokenA_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
}else{
|
||||
flagA = 0;
|
||||
}
|
||||
|
||||
flagB = flagA + 1;
|
||||
|
||||
if(tokenBfd>=0){
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenB_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
tokenWriteLen = HalFileWrite(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenBfd);
|
||||
}
|
||||
|
||||
}else if((tokenAfileSize <= 0)&&(tokenBfileSize > 0)){
|
||||
//only B.creat A
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_CREAT_FS|O_RDWR_FS, 0);
|
||||
if(tokenBfd>=0){
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagB = GetTokenFlag(tokenB_withFlag);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenBfd);
|
||||
}else{
|
||||
flagB = 0;
|
||||
}
|
||||
|
||||
flagA = flagB + 1;
|
||||
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenA_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
}
|
||||
|
||||
}else if((tokenAfileSize > 0)&&(tokenBfileSize > 0)){
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
//get flagA,flagB
|
||||
if(tokenAfd>=0){
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagA = GetTokenFlag(tokenA_withFlag);
|
||||
}else{
|
||||
flagA = 0;
|
||||
}
|
||||
|
||||
if(tokenBfd>=0){
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagB = GetTokenFlag(tokenB_withFlag);
|
||||
}else{
|
||||
flagB = 0;
|
||||
}
|
||||
//write file
|
||||
if(flagA <= flagB){
|
||||
if(tokenAfd>=0){
|
||||
flagA = flagB + 1;
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
}
|
||||
}else{
|
||||
if(tokenBfd>=0){
|
||||
flagB = flagA + 1;
|
||||
(void)memcpy_s(tokenB_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
//close file
|
||||
if(tokenAfd>=0) HalFileClose(tokenAfd);
|
||||
if(tokenBfd>=0) HalFileClose(tokenBfd);
|
||||
free(tokenA_withFlag);
|
||||
free(tokenB_withFlag);
|
||||
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int OEMGetAcKey(char *acKey, unsigned int len)
|
||||
{
|
||||
extern unsigned char A_C[48];
|
||||
memcpy(acKey,A_C,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int OEMGetProdId(char *productId, unsigned int len)
|
||||
{
|
||||
memcpy(productId,PRODUCT_ID,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
//c35d6777954b439aaf2da4a1e3b1fe61
|
||||
static int OEMGetProdKey(char *productKey, unsigned int len)
|
||||
{
|
||||
memcpy(productKey,PRODUCT_KEY,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int HalReadToken(char *token, unsigned int len)
|
||||
{
|
||||
if (token == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMReadToken(token, len);
|
||||
}
|
||||
|
||||
int HalWriteToken(const char *token, unsigned int len)
|
||||
{
|
||||
if ((token == NULL) ||(len==0)){
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMWriteToken(token, len);
|
||||
}
|
||||
|
||||
int HalGetAcKey(char *acKey, unsigned int len)
|
||||
{
|
||||
if (acKey == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMGetAcKey(acKey, len);
|
||||
}
|
||||
|
||||
int HalGetProdId(char *productId, unsigned int len)
|
||||
{
|
||||
if (productId == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMGetProdId(productId, len);
|
||||
}
|
||||
|
||||
int HalGetProdKey(char *productKey, unsigned int len)
|
||||
{
|
||||
if (productKey == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMGetProdKey(productKey, len);
|
||||
}
|
||||
|
||||
void token_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
|
||||
{
|
||||
static char *tokenbuf;
|
||||
static uint8 token_pos = 0;
|
||||
if (argc >= 1)
|
||||
{
|
||||
if (os_strcmp(argv[1], "w") == 0){
|
||||
if (os_strcmp(argv[2], "part1") == 0){
|
||||
if(strlen(argv[3]) <= TOKEN_SIZE){
|
||||
if(tokenbuf == NULL){
|
||||
tokenbuf = (char *)malloc(TOKEN_SIZE+1);
|
||||
}
|
||||
(void)memcpy_s(tokenbuf, TOKEN_SIZE, argv[3], strlen(argv[3]));
|
||||
token_pos = strlen(argv[3]);
|
||||
}else{
|
||||
printf("token part1 len valid.should <= 151\r\n");
|
||||
}
|
||||
}else if (os_strcmp(argv[2], "part2") == 0){
|
||||
if(tokenbuf == NULL){
|
||||
printf("token buff if NULL.should write part1 first!\r\n");
|
||||
}else{
|
||||
(void)memcpy_s(&tokenbuf[token_pos], TOKEN_SIZE, argv[3], strlen(argv[3]));
|
||||
printf("token len : %d = %d + %d. : %s\r\n",token_pos+strlen(argv[3]), token_pos,strlen(argv[3]),tokenbuf);
|
||||
if((token_pos+strlen(argv[3]))==TOKEN_SIZE){
|
||||
HalWriteToken(tokenbuf,TOKEN_SIZE);
|
||||
}else{
|
||||
printf("token len valid.part1+part2 should be 151\r\n");
|
||||
}
|
||||
free(tokenbuf);
|
||||
}
|
||||
|
||||
}else if (os_strcmp(argv[2], "local") == 0){
|
||||
HalWriteToken(tokenstring,sizeof(tokenstring));
|
||||
}else{
|
||||
printf("str len:%d\r\n",strlen(argv[2]));
|
||||
if(strlen(argv[2])==TOKEN_SIZE){
|
||||
HalWriteToken(argv[2],TOKEN_SIZE);
|
||||
}
|
||||
}
|
||||
}else if(os_strcmp(argv[1], "r") == 0){
|
||||
char *tokenRbuf = (char *)malloc(TOKEN_SIZE+1);
|
||||
HalReadToken(tokenRbuf,TOKEN_SIZE);
|
||||
char tmp_c;
|
||||
tmp_c = tokenRbuf[80];
|
||||
tokenRbuf[80] = '\0';
|
||||
printf("tokenbuf =%s",tokenRbuf); //printf part1
|
||||
tokenRbuf[80] = tmp_c;
|
||||
tokenRbuf[151] = '\0';
|
||||
printf("%s\r\n",&tokenRbuf[80]); //printf part2
|
||||
free(tokenRbuf);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const struct cli_command token_clis[] = {
|
||||
|
||||
{"token", "token w/r ", token_command},
|
||||
|
||||
};
|
||||
|
||||
void bk_token_cli_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bk_printf("token cli int \r\n");
|
||||
ret = cli_register_commands(token_clis, sizeof(token_clis) / sizeof(struct cli_command));
|
||||
if (ret)
|
||||
bk_printf("ret: %d token commands fail.\r\n",ret);
|
||||
}
|
||||
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
# LOSCFG_COMPILE_OPTIMIZE is not set
|
||||
# LOSCFG_COMPILE_LTO is not set
|
||||
LOSCFG_PLATFORM_QEMU_RISCV32_VIRT=y
|
||||
LOSCFG_SOC_SERIES_BK7235=y
|
||||
# LOSCFG_POSIX_SEM_API is not set
|
||||
# LOSCFG_POSIX_MQUEUE_API is not set
|
||||
# LOSCFG_POSIX_PIPE_API is not set
|
||||
# LOSCFG_POSIX_SIGNAL_API is not set
|
||||
# LOSCFG_FS_VFS is not set
|
||||
# LOSCFG_PLATFORM_ADAPT is not set
|
||||
# LOSCFG_ENABLE_MAGICKEY is not set
|
||||
# LOSCFG_DEBUG_VERSION is not set
|
||||
LOSCFG_DRIVERS_HDF=y
|
||||
LOSCFG_DRIVERS_HDF_PLATFORM=y
|
||||
LOSCFG_CC_NO_STACKPROTECTOR=y
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"parts": {
|
||||
"product_test_xts_part1": {
|
||||
"module_list": [
|
||||
"//vendor/beken/test_xts_part1:test_xts_part1"
|
||||
]
|
||||
}
|
||||
},
|
||||
"subsystem": "product_test_xts_part1"
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
group("wifi_bk7235") {
|
||||
deps = [
|
||||
|
||||
"//test/xts/tools/lite/hctest:hctest",
|
||||
"//drivers/hdf_core/adapter/khdf/liteos_m:hdf_lite",
|
||||
"//device/board/beken/bk7235x/hcs:hdf_hcs",
|
||||
"//device/board/beken/bk7235x/hdf:bk_hdf_driver",
|
||||
"//drivers/hdf_core/adapter/khdf/liteos_m/core:hdf_core",
|
||||
"//drivers/hdf_core/adapter/khdf/liteos_m/osal:hdf_osal_lite",
|
||||
]
|
||||
}
|
||||
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"product_name": "wifi_bk7235",
|
||||
"ohos_version": "OpenHarmony 3.0",
|
||||
"type": "mini",
|
||||
"version": "3.0",
|
||||
"device_company": "beken",
|
||||
"board": "bk7235x",
|
||||
"kernel_type": "liteos_m",
|
||||
"kernel_version": "3.0",
|
||||
"subsystems": [
|
||||
{
|
||||
"subsystem": "kernel",
|
||||
"components": [
|
||||
{
|
||||
"component": "liteos_m",
|
||||
"features": [
|
||||
"ohos_kernel_liteos_m_lwip_path = \"//device/soc/beken/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2\""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "hiviewdfx",
|
||||
"components": [
|
||||
{ "component": "hilog_lite", "features":[] },
|
||||
{ "component": "hievent_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "systemabilitymgr",
|
||||
"components": [
|
||||
{ "component": "samgr_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "communication",
|
||||
"components": [
|
||||
{ "component": "wifi_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "commonlibrary",
|
||||
"components": [
|
||||
{ "component": "file", "features":[] },
|
||||
{ "component": "timer_task", "features":[] },
|
||||
{ "component": "kal_timer", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "startup",
|
||||
"components": [
|
||||
{ "component": "bootstrap_lite", "features":[] },
|
||||
{ "component": "init_lite", "features":["enable_ohos_startup_init_feature_begetctl_liteos = false"] },
|
||||
{ "component": "syspara_lite", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "security",
|
||||
"components": [
|
||||
{ "component": "huks", "features":
|
||||
[
|
||||
"disable_huks_binary = true",
|
||||
"disable_authenticate = true",
|
||||
"huks_use_lite_storage = true",
|
||||
"huks_use_hardware_root_key = true",
|
||||
"huks_config_file = \"hks_config_lite.h\"",
|
||||
"ohos_security_huks_mbedtls_porting_path = \"//device/soc/beken/bk7235/liteos_m/components/mbedtls\""
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "iothardware",
|
||||
"components": [
|
||||
{ "component": "peripheral", "features":[] }
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
"third_party_dir": "//third_party",
|
||||
"product_adapter_dir": "//vendor/beken/wifi_bk7235/hals",
|
||||
"xts_list": [
|
||||
{
|
||||
"enable": "true",
|
||||
"xts_modules": [
|
||||
"ActsKvStoreTest",
|
||||
"ActsDfxFuncTest",
|
||||
"ActsHieventLiteTest",
|
||||
"ActsSamgrTest",
|
||||
"ActsParameterTest",
|
||||
"ActsWifiServiceTest",
|
||||
"ActsWifiIotTest",
|
||||
"ActsBootstrapTest"
|
||||
]
|
||||
}
|
||||
],
|
||||
"tests_list": [
|
||||
{
|
||||
"enable": "false"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
harmonyos_connect_package_path = "//vendor/huawei/harmonyos_connect"
|
||||
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
ohos_type = "mini"
|
||||
} else if (ohos_kernel_type == "liteos_a") {
|
||||
ohos_type = "small"
|
||||
} else if (ohos_kernel_type == "linux") {
|
||||
ohos_type = "standard"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//applications/iot_solution/device.gni")
|
||||
|
||||
static_library("ota_update_adapter") {
|
||||
sources = [
|
||||
"src/hilink_open_ota_adapter.c",
|
||||
"src/hilink_open_ota_mcu_adapter.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
# "//device/asr/asr582x/drivers/ota"
|
||||
]
|
||||
|
||||
deps = [ "$ohos_vendor_adapter_dir/hals/update:hal_update_static" ]
|
||||
}
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2021. All rights reserved.
|
||||
* Description: OTA适配层接口(需设备厂商实现)
|
||||
*/
|
||||
#ifndef HILINK_OPEN_OTA_ADAPTER_H
|
||||
#define HILINK_OPEN_OTA_ADAPTER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* OTA升级分区1 */
|
||||
#ifndef UPGRADE_FW_BIN1
|
||||
#define UPGRADE_FW_BIN1 0x00
|
||||
#endif
|
||||
|
||||
/* OTA升级分区2 */
|
||||
#ifndef UPGRADE_FW_BIN2
|
||||
#define UPGRADE_FW_BIN2 0x01
|
||||
#endif
|
||||
|
||||
/* 只有MCU升级时立即重启 */
|
||||
#ifndef RESTART_FLAG_NOW
|
||||
#define RESTART_FLAG_NOW 0x01
|
||||
#endif
|
||||
|
||||
/* 有模组时切换分区后再重启 */
|
||||
#ifndef RESTART_FLAG_LATER
|
||||
#define RESTART_FLAG_LATER 0x02
|
||||
#endif
|
||||
|
||||
/* 模组可以重启 */
|
||||
#ifndef MODULE_CAN_REBOOT
|
||||
#define MODULE_CAN_REBOOT 0x01
|
||||
#endif
|
||||
|
||||
/* 模组不能重启 */
|
||||
#ifndef MODULE_CANNOT_REBOOT
|
||||
#define MODULE_CANNOT_REBOOT 0x00
|
||||
#endif
|
||||
|
||||
/* 手动升级 */
|
||||
#ifndef UPDATE_TYPE_MANUAL
|
||||
#define UPDATE_TYPE_MANUAL 0x00
|
||||
#endif
|
||||
|
||||
/* 自动升级 */
|
||||
#ifndef UPDATE_TYPE_AUTO
|
||||
#define UPDATE_TYPE_AUTO 0x01
|
||||
#endif
|
||||
|
||||
/* 返回正常 */
|
||||
#ifndef RETURN_OK
|
||||
#define RETURN_OK 0
|
||||
#endif
|
||||
/* 没有MCU */
|
||||
#ifndef RETURN_ERROR_NO_MCU
|
||||
#define RETURN_ERROR_NO_MCU (-1)
|
||||
#endif
|
||||
/* 返回其他错误 */
|
||||
#ifndef RETURN_ERROR
|
||||
#define RETURN_ERROR (-2)
|
||||
#endif
|
||||
/* MCU不需要升级 */
|
||||
#ifndef RETURN_MCU_NO_NEED_OTA
|
||||
#define RETURN_MCU_NO_NEED_OTA (-3)
|
||||
#endif
|
||||
|
||||
typedef void (*GetOtaVerCb)(const char *version);
|
||||
typedef void (*TrigSelfUpdateCb)(const char *url, const unsigned int size);
|
||||
|
||||
/*
|
||||
* Flash初始化
|
||||
* 返回值是true时,表示初始化正常
|
||||
* 返回值是false时,表示初始化异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashInit(void);
|
||||
|
||||
/*
|
||||
* 判断需要升级的分区
|
||||
* 返回值是UPGRADE_FW_BIN1时,表示升级固件到分区1
|
||||
* 返回值是UPGRADE_FW_BIN2时,表示升级固件到分区2
|
||||
*/
|
||||
unsigned int HILINK_OtaAdapterGetUpdateIndex(void);
|
||||
|
||||
/*
|
||||
* 擦除需要升级的分区
|
||||
* size表示需要擦除的分区大小
|
||||
* 返回值是0时,表示擦除成功
|
||||
* 返回值是-1时,表示擦除失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashErase(unsigned int size);
|
||||
|
||||
/*
|
||||
* 升级数据写入升级的分区
|
||||
* buf表示待写入数据
|
||||
* bufLen表示待写入数据的长度
|
||||
* 返回值是0时,表示写入成功
|
||||
* 返回值是-1时,表示写入失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int bufLen);
|
||||
|
||||
/*
|
||||
* 读取升级分区数据
|
||||
* offset表示读写偏移
|
||||
* buf表示输出数据的内存地址
|
||||
* bufLen表示输出数据的内存长度
|
||||
* 返回值是0时,表示读取成功
|
||||
* 返回值是-1时,表示读取失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int bufLen);
|
||||
|
||||
/*
|
||||
* 分区升级结束
|
||||
* 返回值是true时,表示结束正常
|
||||
* 返回值是false时,表示结束异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashFinish(void);
|
||||
|
||||
/* 获取升级区间最大长度 */
|
||||
unsigned int HILINK_OtaAdapterFlashMaxSize(void);
|
||||
|
||||
/*
|
||||
* 根据标志重启模组
|
||||
* flag表示重启标志
|
||||
* 当flag是RESTART_FLAG_NOW时,表示只有MCU升级时立即重启
|
||||
* 当flag是RESTART_FLAG_LATER时,表示有模组时切换分区后再重启
|
||||
*/
|
||||
void HILINK_OtaAdapterRestart(int flag);
|
||||
|
||||
/*
|
||||
* 开始模组升级
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将开始启动升级流程
|
||||
* 返回值是RETURN_ERROR时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:在手动场景场景下,HiLink SDK在接收到用户发出的升级指令后,将直接调用此接口;
|
||||
* 在自动升级场景下,当HiLink SDK在调用HilinkGetRebootFlag接口返回值是MODULE_CAN_REBOOT时,HiLink SDK将调用此接口。
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_OtaStartProcess(int type);
|
||||
|
||||
/*
|
||||
* 模组升级结束
|
||||
* status表示升级结果
|
||||
* 当status是100时,表示升级成功
|
||||
* 当status不是100时,表示升级失败
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将置升级标志或切换运行区标志
|
||||
* 返回值不是RETURN_OK时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:HiLink SDK在将固件写入到OTA升级区后,且完整性校验通过后,将调用厂商适配的此接口;
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等;升级类型是否为自动升级可参考接口HilinkOtaStartProcess的参数type的描述。
|
||||
*/
|
||||
int HILINK_OtaEndProcess(int status);
|
||||
|
||||
/*
|
||||
* 判断模组是否能立即升级并重启
|
||||
* 返回值是MODULE_CAN_REBOOT时,表示模组可以立即升级并重启,HiLink SDK将开始自动升级流程。
|
||||
* 返回值是MODULE_CANNOT_REBOOT时,表示模组不能立即升级并重启,HiLink SDK将不进行本次自动升级流程。
|
||||
* 注意:在用户同意设备可以自动升级的情况下,HiLink SDK调用此接口获取设备当前业务状态下,模组是否可以立即升级并重启的标志。
|
||||
* 只有当设备处于业务空闲状态时,接口才可以返回MODULE_CAN_REBOOT。
|
||||
* 当设备处于业务非空闲状态时,接口返回MODULE_CANNOT_REBOOT。
|
||||
*/
|
||||
int HILINK_GetRebootFlag(void);
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本检测
|
||||
* 检测到的版本,sdk将通过cb回调函数上报。如果不需要获取版本号,则可将cb置空。
|
||||
* 上报的version如果为空,则未成功获取到新版本。
|
||||
* 注意:1、建议调用频次最多一天一次
|
||||
* 2、首次通过手机配网成功后不能调用,建议连云成功后至少5s后调用
|
||||
*/
|
||||
void HILINK_TrigOtaVersionCheck(GetOtaVerCb cb);
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本升级
|
||||
* 检测到的版本,sdk将通过cb回调函数触发升级
|
||||
*/
|
||||
void HILINK_TrigOtaSelfUpdate(TrigSelfUpdateCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
|
||||
* Description: MCU OTA适配层接口(需设备厂商实现)
|
||||
*/
|
||||
#ifndef HILINK_OPEN_OTA_MCU_ADAPTER_H
|
||||
#define HILINK_OPEN_OTA_MCU_ADAPTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 返回正常 */
|
||||
#ifndef RETURN_OK
|
||||
#define RETURN_OK 0
|
||||
#endif
|
||||
|
||||
/* 没有MCU */
|
||||
#ifndef RETURN_ERROR_NO_MCU
|
||||
#define RETURN_ERROR_NO_MCU (-1)
|
||||
#endif
|
||||
|
||||
/* MCU返回其他错误 */
|
||||
#ifndef RETURN_ERROR
|
||||
#define RETURN_ERROR (-2)
|
||||
#endif
|
||||
|
||||
/* MCU不需要升级 */
|
||||
#ifndef RETURN_MCU_NO_NEED_OTA
|
||||
#define RETURN_MCU_NO_NEED_OTA (-3)
|
||||
#endif
|
||||
|
||||
/* 手动升级 */
|
||||
#ifndef UPDATE_TYPE_MANUAL
|
||||
#define UPDATE_TYPE_MANUAL 0x00
|
||||
#endif
|
||||
|
||||
/* 自动升级 */
|
||||
#ifndef UPDATE_TYPE_AUTO
|
||||
#define UPDATE_TYPE_AUTO 0x01
|
||||
#endif
|
||||
|
||||
/* 开始发送MCU数据 */
|
||||
#ifndef START_SEND_DATA
|
||||
#define START_SEND_DATA 0
|
||||
#endif
|
||||
|
||||
/* 发送MCU数据结束 */
|
||||
#ifndef STOP_SEND_DATA
|
||||
#define STOP_SEND_DATA 1
|
||||
#endif
|
||||
|
||||
/* 异常终止 */
|
||||
#ifndef SEND_DATA_ERROR
|
||||
#define SEND_DATA_ERROR 2
|
||||
#endif
|
||||
|
||||
typedef int (*RptUpgProgressFlagCb)(void);
|
||||
|
||||
/*
|
||||
* 获取MCU当前版本
|
||||
* version表示版本字符串
|
||||
* inLen表示输入字符串长度
|
||||
* outLen表示输出字符串长度
|
||||
* 返回值是RETURN_OK时,表示获取成功
|
||||
* 返回值是RETURN_ERROR_NO_MCU时,表示没有MCU
|
||||
* 返回值是RETURN_ERROR时,表示获取失败
|
||||
* 注意:如果获取不到MCU的版本,则不对MCU进行升级。
|
||||
* 建议厂商在MCU正常启动后,或升级启动后,就将MCU的版本号传递给模组,确保模组可以获取到MCU的版本。
|
||||
*/
|
||||
int HILINK_GetMcuVersion(char *version, unsigned int inLen, unsigned int *outLen);
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知MCU固件传输的状态
|
||||
* flag表示升级流程标志
|
||||
* 当flag是START_SEND_DATA时,表示通知模组即将开始发送MCU固件数据包
|
||||
* 当flag是STOP_SEND_DATA时,表示通知模组完整的MCU固件包已发送完成
|
||||
* 当flag是SEND_DATA_ERROR时,表示通知模组本次MCU固件升级异常终止
|
||||
* len表示MCU固件包的大小
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,表示处理失败,HiLink SDK将终止本次MCU升级流程
|
||||
* 注意:当flag是STOP_SEND_DATA时,此接口需返回MCU侧固件升级的结果;当flag是其它值时,需返回接口接收到此消息后的处理结果。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_NotifyOtaStatus(int flag, unsigned int len, unsigned int type);
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知厂商发送MCU固件文件数据
|
||||
* data表示发送的数据
|
||||
* len表示发送的数据的长度
|
||||
* offset表示发送的数据起始位置相对于完整固件包的偏移量
|
||||
* 此接口需要返回MCU接收这部分数据的处理结果
|
||||
* 返回值是RETURN_OK时,模组将通知的数据正确发送给MCU,且MCU正确处理发送的数据,HiLink SDK将继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,模组或MCU未能正常处理通知的MCU的固件文件数据,HiLink SDK将终止本次MCU固件升级流程
|
||||
*/
|
||||
int HILINK_NotifyOtaData(const unsigned char *data, unsigned int len, unsigned int offset);
|
||||
|
||||
/*
|
||||
* 产品OTA升级时下载升级包进度为100%后会重启, APP上显示设备重启中
|
||||
* 然后等设备起来后上报进度0, APP上才会显示升级成功
|
||||
* 通过回调函数cb来设置Hilink Sdk被拉起后是否立即向APP上报进度0
|
||||
* cb返回1时hilink sdk被拉起后不会立即上报进度0,
|
||||
* 上报时机由产品自己决定,调用hilink_ota_rpt_prg进行上报
|
||||
* cb返回0时hilink sdk被拉起后会立即上报进度0
|
||||
* 产品根据自身升级情况判断是否需要注册cb,如不注册则默认hilink sdk被拉起后会立即上报进度0
|
||||
*/
|
||||
void HILINK_PowerOnRptUpgProgress(RptUpgProgressFlagCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* HILINK_OPEN_OTA_BRIDGE_ADAPTER_H */
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
|
||||
* Description: OTA适配实现 (需设备厂商实现)
|
||||
*/
|
||||
#include "hilink_open_ota_adapter.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#define DOWNLOAD_PATITION_ADDR 0x253000 //68+2048+300KB
|
||||
#define DOWNLOAD_PATITION_LEN 0x187000 //1536KB
|
||||
static unsigned int write_length = 0;
|
||||
#define HILINK_OK 0
|
||||
#define HILINK_ERROR -1
|
||||
|
||||
/*
|
||||
* Flash初始化
|
||||
* 返回值是true时,表示初始化正常
|
||||
* 返回值是false时,表示初始化异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashInit(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashInit start\r\n");
|
||||
IoTFlashInit();
|
||||
write_length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 判断需要升级的分区
|
||||
* 返回值是UPGRADE_FW_BIN1时,表示升级固件到分区1
|
||||
* 返回值是UPGRADE_FW_BIN2时,表示升级固件到分区2
|
||||
*/
|
||||
unsigned int HILINK_OtaAdapterGetUpdateIndex(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterGetUpdateIndex start\r\n");
|
||||
return UPGRADE_FW_BIN1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 擦除需要升级的分区
|
||||
* size表示需要擦除的分区大小
|
||||
* 返回值是ILINK_OK时,表示擦除成功
|
||||
* 返回值是HILINK_ERROR时,表示擦除失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashErase(unsigned int size)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashErase start size=%d\r\n",size);
|
||||
return IoTFlashErase(DOWNLOAD_PATITION_ADDR,DOWNLOAD_PATITION_LEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* 升级数据写入升级的分区
|
||||
* buf表示待写入数据
|
||||
* bufLen表示待写入数据的长度
|
||||
* 返回值是HILINK_OK时,表示写入成功
|
||||
* 返回值是HILINK_ERROR时,表示写入失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashWrite(const unsigned char *buf, unsigned int bufLen)
|
||||
{
|
||||
//printf("HILINK_OtaAdapterFlashWrite start\r\n");
|
||||
#if 1
|
||||
int ret;
|
||||
if (bufLen == 0)
|
||||
{
|
||||
return HILINK_OK;
|
||||
}
|
||||
if (buf == NULL)
|
||||
{
|
||||
return HILINK_ERROR;
|
||||
}
|
||||
|
||||
ret = IoTFlashWrite(DOWNLOAD_PATITION_ADDR + write_length, bufLen, buf, 0);
|
||||
|
||||
write_length += bufLen;
|
||||
if(ret == 0)
|
||||
return HILINK_OK;
|
||||
else
|
||||
return HILINK_ERROR;
|
||||
#else
|
||||
return HILINK_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 读取升级分区数据
|
||||
* offset表示读写偏移
|
||||
* buf表示输出数据的内存地址
|
||||
* bufLen表示输出数据的内存长度
|
||||
* 返回值是HILINK_OK时,表示读取成功
|
||||
* 返回值是HILINK_ERROR时,表示读取失败
|
||||
*/
|
||||
int HILINK_OtaAdapterFlashRead(unsigned int offset, unsigned char *buf, unsigned int bufLen)
|
||||
{
|
||||
//printf("HILINK_OtaAdapterFlashRead start\r\n");
|
||||
#if 1
|
||||
int ret;
|
||||
if ( (buf == NULL) || (bufLen == 0))
|
||||
{
|
||||
return HILINK_ERROR;
|
||||
}
|
||||
ret = IoTFlashRead(DOWNLOAD_PATITION_ADDR + offset, bufLen, buf);
|
||||
|
||||
if(ret == 0)
|
||||
return HILINK_OK;
|
||||
else
|
||||
return HILINK_ERROR;
|
||||
#else
|
||||
return HILINK_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* 分区升级结束
|
||||
* 返回值是true时,表示结束正常
|
||||
* 返回值是false时,表示结束异常
|
||||
*/
|
||||
bool HILINK_OtaAdapterFlashFinish(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashFinish start\r\n");
|
||||
IoTFlashDeinit();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 获取升级区间最大长度 */
|
||||
unsigned int HILINK_OtaAdapterFlashMaxSize(void)
|
||||
{
|
||||
printf("HILINK_OtaAdapterFlashMaxSize start\r\n");
|
||||
|
||||
return DOWNLOAD_PATITION_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据标志重启模组
|
||||
* flag表示重启标志
|
||||
* 当flag是RESTART_FLAG_NOW时,表示只有MCU升级时立即重启
|
||||
* 当flag是RESTART_FLAG_LATER时,表示有模组时切换分区后再重启
|
||||
*/
|
||||
void HILINK_OtaAdapterRestart(int flag)
|
||||
{
|
||||
printf("HILINK_OtaAdapterRestart start\r\n");
|
||||
reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 开始模组升级
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将开始启动升级流程
|
||||
* 返回值是RETURN_ERROR时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:在手动场景场景下,HiLink SDK在接收到用户发出的升级指令后,将直接调用此接口;
|
||||
* 在自动升级场景下,当HiLink SDK在调用HilinkGetRebootFlag接口返回值是MODULE_CAN_REBOOT时,HiLink SDK将调用此接口。
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_OtaStartProcess(int type)
|
||||
{
|
||||
printf("HILINK_OtaStartProcess start type =%d\r\n",type);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 模组升级结束
|
||||
* status表示升级结果
|
||||
* 当status是100时,表示升级成功
|
||||
* 当status不是100时,表示升级失败
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK将置升级标志或切换运行区标志
|
||||
* 返回值不是RETURN_OK时,表示处理不成功,HiLink SDK将终止本次升级流程
|
||||
* 注意:HiLink SDK在将固件写入到OTA升级区后,且完整性校验通过后,将调用厂商适配的此接口;
|
||||
* 厂商可在此接口中完成和升级流程相关的处理。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等;升级类型是否为自动升级可参考接口HilinkOtaStartProcess的参数type的描述。
|
||||
*/
|
||||
int HILINK_OtaEndProcess(int status)
|
||||
{
|
||||
printf("HILINK_OtaEndProcess start status=%d\r\n",status);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断模组是否能立即升级并重启
|
||||
* 返回值是MODULE_CAN_REBOOT时,表示模组可以立即升级并重启,HiLink SDK将开始自动升级流程。
|
||||
* 返回值是MODULE_CANNOT_REBOOT时,表示模组不能立即升级并重启,HiLink SDK将不进行本次自动升级流程。
|
||||
* 注意:在用户同意设备可以自动升级的情况下,HiLink SDK调用此接口获取设备当前业务状态下,模组是否可以立即升级并重启的标志。
|
||||
* 只有当设备处于业务空闲状态时,接口才可以返回MODULE_CAN_REBOOT。
|
||||
* 当设备处于业务非空闲状态时,接口返回MODULE_CANNOT_REBOOT。
|
||||
*/
|
||||
int HILINK_GetRebootFlag(void)
|
||||
{
|
||||
printf("HILINK_GetRebootFlag start\r\n");
|
||||
return MODULE_CAN_REBOOT;
|
||||
}
|
||||
|
||||
/*
|
||||
* 触发设备的ota新版本升级
|
||||
* 检测到的版本,sdk将通过cb回调函数触发升级
|
||||
*/
|
||||
void HILINK_TrigOtaSelfUpdate(TrigSelfUpdateCb cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
|
||||
* Description: 外挂MCU升级适配实现 (需设备厂商实现)
|
||||
*/
|
||||
|
||||
#include "hilink_open_ota_mcu_adapter.h"
|
||||
|
||||
/*
|
||||
* 获取MCU当前版本
|
||||
* version表示版本字符串
|
||||
* inLen表示输入字符串长度
|
||||
* outLen表示输出字符串长度
|
||||
* 返回值是RETURN_OK时,表示获取成功
|
||||
* 返回值是RETURN_ERROR_NO_MCU时,表示没有MCU
|
||||
* 返回值是RETURN_ERROR时,表示获取失败
|
||||
* 返回值是RETURN_MCU_NO_NEED_OTA时,表示不需要MCU升级
|
||||
* 注意:如果获取不到MCU的版本,则不对MCU进行升级。
|
||||
* 建议厂商在MCU正常启动后,或升级启动后,就将MCU的版本号传递给模组,确保模组可以获取到MCU的版本。
|
||||
*/
|
||||
int HILINK_GetMcuVersion(char *version, unsigned int inLen, unsigned int *outLen)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知MCU固件传输的状态
|
||||
* flag表示升级流程标志
|
||||
* 当flag是START_SEND_DATA时,表示通知模组即将开始发送MCU固件数据包
|
||||
* 当flag是STOP_SEND_DATA时,表示通知模组完整的MCU固件包已发送完成
|
||||
* 当flag是SEND_DATA_ERROR时,表示通知模组本次MCU固件升级异常终止
|
||||
* len表示MCU固件包的大小
|
||||
* type表示升级类型
|
||||
* 当type是UPDATE_TYPE_MANUAL时,表示本次升级流程是由用户主动发起的手动升级
|
||||
* 当type是UPDATE_TYPE_AUTO时,表示本次升级流程是经过用户同意的自动升级
|
||||
* 返回值是RETURN_OK时,表示处理成功,HiLink SDK继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,表示处理失败,HiLink SDK将终止本次MCU升级流程
|
||||
* 注意:当flag是STOP_SEND_DATA时,此接口需返回MCU侧固件升级的结果;当flag是其它值时,需返回接口接收到此消息后的处理结果。
|
||||
* 开机后10分钟到1小时内随机时间检测一次是否有新版本,之后以当前时间为起点,23小时加1小时内随机值周期性检测新版本。
|
||||
* 如果用户打开了自动升级开关,检测到有新版本并且是可以重启的情况下,就进行新版本的下载,下载完成后自动重启。
|
||||
* 自动升级流程可能在凌晨进行,因此厂商在实现升级流程相关功能时,确保在升级的下载安装固件和重启设备时避免对用户产生
|
||||
* 影响,比如发出声音,光亮等。
|
||||
*/
|
||||
int HILINK_NotifyOtaStatus(int flag, unsigned int len, unsigned int type)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* HiLink SDK调用厂商适配的此接口通知厂商发送MCU固件文件数据
|
||||
* data表示发送的数据
|
||||
* len表示发送的数据的长度
|
||||
* offset表示发送的数据起始位置相对于完整固件包的偏移量
|
||||
* 此接口需要返回MCU接收这部分数据的处理结果
|
||||
* 返回值是RETURN_OK时,模组将通知的数据正确发送给MCU,且MCU正确处理发送的数据,HiLink SDK将继续正常处理后续流程
|
||||
* 返回值是RETURN_ERROR时,模组或MCU未能正常处理通知的MCU的固件文件数据,HiLink SDK将终止本次MCU固件升级流程
|
||||
*/
|
||||
int HILINK_NotifyOtaData(const unsigned char *data, unsigned int len, unsigned int offset)
|
||||
{
|
||||
/* 厂商实现此接口 */
|
||||
return RETURN_OK;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#import("//applications/iot_solution/device.gni")
|
||||
|
||||
oem_common_deps = [
|
||||
# "//build/lite/config/component/cJSON:cjson_shared",
|
||||
# "//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
|
||||
config("oem_common_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/cJSON/",
|
||||
"//third_party/mbedtls/include",
|
||||
"//kernel/liteos_m/components/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
# "//device/asr/asr582x/drivers/kv/include/",
|
||||
]
|
||||
defines = []
|
||||
}
|
||||
|
||||
static_library("oem_auth_result_storage") {
|
||||
sources = [ "src/oem_auth_result_storage.c" ]
|
||||
configs += [ ":oem_common_config" ]
|
||||
deps = oem_common_deps
|
||||
}
|
||||
|
||||
static_library("oem_auth_config") {
|
||||
sources = [ "src/oem_auth_config.c" ]
|
||||
configs += [ ":oem_common_config" ]
|
||||
deps = oem_common_deps
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: interface file for kitframework client
|
||||
* Author: yangzuxun
|
||||
* Create: 2020-07-20
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_KIT_FRAMEWORK_CLIENT_H
|
||||
#define HOS_LITE_KIT_FRAMEWORK_CLIENT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
// request auth result
|
||||
#define ERR_OK 0
|
||||
#define SERVICE_UNAVAILABLE (-1)
|
||||
#define INVALID_PARAM (-2)
|
||||
|
||||
#define PASS 0
|
||||
#define FAIL (-1)
|
||||
#define UNKNOWN (-2)
|
||||
|
||||
// define authentication control policy
|
||||
#define POLICY_ALERT (0x1 << 0) // 警告,kit自行决定
|
||||
#define POLICY_DENY (0x1 << 1) // 拒绝
|
||||
#define POLICY_PASS (0x1 << 2) // 放通
|
||||
#define POLICY_INVISBLE (0x1 << 3) // 设备不可见
|
||||
|
||||
// kit id
|
||||
#define DV_KIT "DvKit"
|
||||
#define CAST_KIT "CastKit"
|
||||
#define HI_LINK "HiLinkKit"
|
||||
#define HI_CAR "HiCarKit"
|
||||
#define SHARE "ShareKit"
|
||||
#define MEET_TIME "MeetTimeKit"
|
||||
#define ONE_HOP "OneHopKit"
|
||||
#define ONE_TAG "OneTagKit"
|
||||
|
||||
// CheckModuleValid return value
|
||||
#define RET_OK 1
|
||||
#define RET_FALSE 0
|
||||
#define RET_INVALID (-1)
|
||||
|
||||
typedef enum {
|
||||
TYPE_AA, // hap or static form
|
||||
TYPE_DEBUG, // debug version
|
||||
TYPE_BDREPORT, // big data report module
|
||||
TYPE_D2D, // D2D module
|
||||
TYPE_D2C, // D2C module
|
||||
} CheckType;
|
||||
|
||||
typedef struct AuthStatus AuthStatus;
|
||||
typedef void (*IAuthResultCallback)(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to initial the authtication client and connect to the
|
||||
* kit server, and return the connect status. The function must be called before
|
||||
* RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback).
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
* @return error_code: REQ_OK or SERVICE_UNAVAILABLE or INVALID_PARAM
|
||||
*/
|
||||
int32_t CreateKitFrameworkClient(const char* kitId);
|
||||
|
||||
/**
|
||||
* @brief The function is used to trigger device auth, and return the auth result.
|
||||
* The caller can only call the function without calling CreateKitFrameworkClient(const char* kitId) before.
|
||||
* @param networkId: the name defined in soft-bus, NULL for local device.
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
* @param callback: the Auth check result callback.
|
||||
* @return error_code: REQ_OK or SERVICE_UNAVAILABLE or INVALID_PARAM
|
||||
*/
|
||||
int32_t RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback);
|
||||
|
||||
/**
|
||||
* @brief The function is used to close the connection of kit server and release the client.
|
||||
* The function must be called after
|
||||
* RequestAuth(const char* networkId, const char* kitId, IAuthResultCallback callback).
|
||||
* @param kitId: the Kit identity(package name) which describe the kits to be checked.
|
||||
*/
|
||||
void CloseKitFrameworkClient(const char* kitId);
|
||||
|
||||
/**
|
||||
* @brief The function is used to check the type whether exists or not
|
||||
* @param type: the check module type.
|
||||
* @return error_code: RET_OK or RET_FALSE or RET_INVALID
|
||||
*/
|
||||
int32_t CheckModuleValid(CheckType type);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get device auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of device.
|
||||
*/
|
||||
int32_t GetDeviceStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get system auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of system.
|
||||
*/
|
||||
int32_t GetSystemStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get kit auth status;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth status of kit.
|
||||
*/
|
||||
int32_t GetKitStatus(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get kit auth policy;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return The auth policy of kit.
|
||||
*/
|
||||
int32_t GetAuthPolicy(const AuthStatus* status);
|
||||
|
||||
/**
|
||||
* @brief The function is used to get ticket;
|
||||
* @param[in] status: The auth status of kit.
|
||||
* @return NULL or ticket , max size is 256.
|
||||
*/
|
||||
const char* GetTicket(const AuthStatus* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: headfile of oem_auth_config
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_OEM_AUTH_CONFIG_H
|
||||
#define HOS_LITE_OEM_AUTH_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "mbedtls/x509_crt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief read authentication's server info from device which implemented by OEM.
|
||||
* format: server1:port1;server2:port2; ...
|
||||
* @param port: pointer of server info's buffer.
|
||||
* @param len: length of server info's buffer, max value is 256.
|
||||
* The max length for signal NV srtuct is 252 Bytes, so please be careful if the server info is save as NV.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadAuthServerInfo(char* buff, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief load kit's id and verison information from device which implemented by OEM.
|
||||
* @return char* not NULL means load succeed, NULL is means OEM haven't set kit infos or no others kit to authenticate
|
||||
* example : NULL means no others kit
|
||||
* "{\"KitInfos\":[]}" means no others kit
|
||||
* "{\"KitInfos\":[{\"HiLinkKit\":\"1.0.0\"},{\"DvKit\":\"1.0.1\"}]}" means with HiLink and DvKit
|
||||
*/
|
||||
char* OEMLoadKitInfos(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HOS_LITE_OEM_AUTH_CONFIG_H */
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: headfile of oem_auth_result_storage
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
#ifndef HOS_LITE_OEM_AUTH_RESULT_STORAGE_H
|
||||
#define HOS_LITE_OEM_AUTH_RESULT_STORAGE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief check whether the temperature of the device's flash chip is over limit or not.
|
||||
* @return true is over limit.
|
||||
*/
|
||||
bool OEMIsOverTemperatureLimit(void);
|
||||
|
||||
/**
|
||||
* @brief check reset flag is exist or not which implemented by OEM.
|
||||
* @return true is reset flag existed, false is not.
|
||||
*/
|
||||
bool OEMIsResetFlagExist(void);
|
||||
|
||||
/**
|
||||
* @brief create reset flag in device which implemented by OEM.
|
||||
* @return 0 is create succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMCreateResetFlag(void);
|
||||
|
||||
/**
|
||||
* @brief delete reset flag in device which implemented by OEM.
|
||||
* @return 0 is create succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteResetFlag(void);
|
||||
|
||||
/**
|
||||
* @brief check auth status file is exist or not which implemented by OEM.
|
||||
* @return true is auth status file existed, false is not.
|
||||
*/
|
||||
bool OEMIsAuthStatusExist(void);
|
||||
|
||||
/**
|
||||
* @brief write auth status to device which implemented by OEM.
|
||||
* @param data: pointer of data which to be written.
|
||||
* @param len: length of data which to be written.
|
||||
* @return 0 is written succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMWriteAuthStatus(const char* data, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief read auth status from device which implemented by OEM.
|
||||
* @param buffer: pointer of auth status's buffer.
|
||||
* @param bufferLen: length of auth status's buffer.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadAuthStatus(char* buffer, uint32_t bufferLen);
|
||||
|
||||
/**
|
||||
* @brief delete auth status file from device which implemented by OEM.
|
||||
* @return 0 is delete succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteAuthStatus(void);
|
||||
|
||||
/**
|
||||
* @brief get auth status's content size from device which implemented by OEM.
|
||||
* @param len: pointer of auth status's content size.
|
||||
* @return 0 is succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMGetAuthStatusFileSize(uint32_t* len);
|
||||
|
||||
/**
|
||||
* @brief check ticket file is exist or not which implemented by OEM.
|
||||
* @return true is ticket file existed, false is not.
|
||||
*/
|
||||
bool OEMIsTicketExist(void);
|
||||
|
||||
/**
|
||||
* @brief write ticket to device which implemented by OEM.
|
||||
* @param data: pointer of data which to be written.
|
||||
* @param len: length of data which to be written.
|
||||
* @return 0 is written succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMWriteTicket(const char* data, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief read ticket from device which implemented by OEM.
|
||||
* @param buffer: pointer of ticket's buffer.
|
||||
* @param bufferLen: length of ticket's buffer.
|
||||
* @return 0 is read succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMReadTicket(char* buffer, uint32_t bufferLen);
|
||||
|
||||
/**
|
||||
* @brief delete ticket file from device which implemented by OEM.
|
||||
* @return 0 is delete succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMDeleteTicket(void);
|
||||
|
||||
/**
|
||||
* @brief get ticket's content size from device which implemented by OEM.
|
||||
* @param len: pointer of ticket's content size.
|
||||
* @return 0 is succeed, others is failed.
|
||||
*/
|
||||
int32_t OEMGetTicketFileSize(uint32_t* len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HOS_LITE_OEM_AUTH_RESULT_STORAGE_H */
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: implement of oem_auth_config
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#include "oem_auth_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#define HCS_HILINKKIT
|
||||
#define KIT_ID_LEN 40
|
||||
|
||||
typedef const char *(*KitGetVerFunc)();
|
||||
|
||||
typedef struct KitGetVerInfo
|
||||
{
|
||||
char kitId[KIT_ID_LEN + 1];
|
||||
KitGetVerFunc kitGetVerFunc;
|
||||
} KitGetVerInfo;
|
||||
|
||||
#ifdef HCS_DVKIT
|
||||
extern const char *DvKit_GetVersion();
|
||||
#endif
|
||||
|
||||
#ifdef HCS_HILINKKIT
|
||||
// extern const char* HiLinkKit_GetVersion();
|
||||
const char *HiLinkKit_GetVersion()
|
||||
{
|
||||
return "1.0.0";
|
||||
}
|
||||
#endif
|
||||
|
||||
KitGetVerInfo g_kitGetVerInfo[] = {
|
||||
#ifdef HCS_DVKIT
|
||||
{"DvKit", DvKit_GetVersion},
|
||||
#endif
|
||||
#ifdef HCS_HILINKKIT
|
||||
{"HiLinkKit", HiLinkKit_GetVersion},
|
||||
#endif
|
||||
{0, NULL}};
|
||||
#define TOTAL_TIMEOUT 10000
|
||||
#define KIT_INFO_JSON_KEY "KitInfos"
|
||||
uint32_t OEMGetTotalTimeout()
|
||||
{
|
||||
return TOTAL_TIMEOUT;
|
||||
}
|
||||
|
||||
int32_t OEMReadAuthServerInfo(char *buff, uint32_t len)
|
||||
{
|
||||
if (buff == NULL || len == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *OEMLoadKitInfos(void)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
if (root == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
cJSON *infos = cJSON_CreateArray();
|
||||
if (infos == NULL)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint32_t kitCount = sizeof(g_kitGetVerInfo) / sizeof(KitGetVerInfo);
|
||||
for (uint32_t i = 0; i < kitCount; i++)
|
||||
{
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
if (obj == NULL)
|
||||
{
|
||||
printf("OEM Adapter: Create json object failed\n");
|
||||
continue;
|
||||
}
|
||||
const char *key = g_kitGetVerInfo[i].kitId;
|
||||
KitGetVerFunc kitGetVerFunc = g_kitGetVerInfo[i].kitGetVerFunc;
|
||||
if (key == NULL || strlen(key) == 0 || kitGetVerFunc == NULL)
|
||||
{
|
||||
cJSON_Delete(obj);
|
||||
continue;
|
||||
}
|
||||
const char *value = (kitGetVerFunc)();
|
||||
if (value == NULL || strlen(value) == 0 || cJSON_AddStringToObject(obj, key, value) == NULL)
|
||||
{
|
||||
printf("OEM Adapter: Add kit info %s to json object failed\n", key);
|
||||
cJSON_Delete(obj);
|
||||
continue;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(infos, obj))
|
||||
{
|
||||
cJSON_Delete(obj);
|
||||
printf("OEM Adapter: Add kit info %s to json array failed\n", key);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cJSON_AddItemToObject(root, KIT_INFO_JSON_KEY, infos))
|
||||
{
|
||||
printf("OEM Adapter: Add kit infos to json object failed\n");
|
||||
cJSON_Delete(infos);
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
char *result = cJSON_PrintUnformatted(root);
|
||||
cJSON_Delete(root);
|
||||
return result;
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
* Description: implement of oem_auth_result_storage
|
||||
* Author: Kit Framework group
|
||||
* Create: 2020-12-26
|
||||
*/
|
||||
|
||||
#include "oem_auth_result_storage.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "utils_file.h"
|
||||
|
||||
#define RESET_FILE_NAME "auth_reset"
|
||||
#define TICKET_FILE_NAME "auth_ticket"
|
||||
#define AUTH_STATS_FILE_NAME "auth_authstats"
|
||||
|
||||
#define WRITE_FLASH_MAX_TEMPERATURE 80
|
||||
static const uint32_t MAX_FILE_BYTES_LIMIT = 5120;
|
||||
|
||||
bool OEMIsOverTemperatureLimit(void)//???¨¨?D?¦Ì?D??
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsFileExist(const char* path)
|
||||
{
|
||||
printf("IsFileExist start path=%s\r\n",path);
|
||||
if(path == NULL)
|
||||
return false;
|
||||
int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
(void)UtilsFileClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t CreateFile(const char* path)
|
||||
{
|
||||
printf("CreateFile start path=%s\r\n",path);
|
||||
if(path == NULL)
|
||||
return false;
|
||||
int32_t fd = UtilsFileOpen(path, O_CREAT_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
(void)UtilsFileClose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int32_t WriteFile(const char* path,const char* data,uint32_t datalen,int flag)
|
||||
{
|
||||
printf("WriteFile start path=%s\r\n",path);
|
||||
if(path == NULL || data == NULL || datalen == 0)
|
||||
{
|
||||
printf("WriteFile data invalid\r\n");
|
||||
return -1;
|
||||
}
|
||||
if(datalen > MAX_FILE_BYTES_LIMIT)
|
||||
{
|
||||
printf("WriteFile data over limit\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(OEMIsOverTemperatureLimit())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int32_t fd = UtilsFileOpen(path, flag, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("WriteFile open failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if(UtilsFileWrite(fd, data, datalen) != datalen)
|
||||
{
|
||||
printf("WriteFile write failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)UtilsFileClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadFile(const char* path,const char* buffer,uint32_t bufferlen)
|
||||
{
|
||||
printf("ReadFile start path=%s\r\n",path);
|
||||
if(path == NULL || buffer == NULL || bufferlen == 0)
|
||||
{
|
||||
printf("ReadFile data invalid\r\n");
|
||||
return -1;
|
||||
}
|
||||
if(!IsFileExist(path))
|
||||
{
|
||||
printf("ReadFile file not exsit\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t filesize = 0;
|
||||
if(UtilsFileStat(path,&filesize) != 0)
|
||||
{
|
||||
printf("ReadFile stat file failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(filesize > bufferlen)
|
||||
{
|
||||
printf("ReadFile read data over buffer lenth\r\n");
|
||||
return -1;
|
||||
}
|
||||
int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("ReadFile open failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if(UtilsFileRead(fd, buffer, filesize) != filesize)
|
||||
{
|
||||
printf("ReadFile read data failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)UtilsFileClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t DeleteFile(const char* path)
|
||||
{
|
||||
UtilsFileDelete(path);
|
||||
}
|
||||
|
||||
bool OEMIsResetFlagExist(void)
|
||||
{
|
||||
return IsFileExist(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMCreateResetFlag(void)
|
||||
{
|
||||
return CreateFile(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteResetFlag(void)
|
||||
{
|
||||
return DeleteFile(RESET_FILE_NAME);
|
||||
}
|
||||
|
||||
bool OEMIsAuthStatusExist(void)
|
||||
{
|
||||
return IsFileExist(AUTH_STATS_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMWriteAuthStatus(const char* data, uint32_t len)
|
||||
{
|
||||
if(data == NULL || len == 0)
|
||||
return -1;
|
||||
|
||||
return WriteFile(AUTH_STATS_FILE_NAME,data,len,O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS);
|
||||
}
|
||||
|
||||
int32_t OEMReadAuthStatus(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
if(buffer == NULL || bufferLen == 0)
|
||||
return -1;
|
||||
|
||||
return ReadFile(AUTH_STATS_FILE_NAME,buffer,bufferLen);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteAuthStatus(void)
|
||||
{
|
||||
return DeleteFile(AUTH_STATS_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMGetAuthStatusFileSize(uint32_t* len)
|
||||
{
|
||||
printf("OEMGetAuthStatusFileSize len=%p\r\n",len);
|
||||
if(len == NULL)
|
||||
return -1;
|
||||
|
||||
return UtilsFileStat(AUTH_STATS_FILE_NAME,len);
|
||||
}
|
||||
|
||||
bool OEMIsTicketExist(void)
|
||||
{
|
||||
return IsFileExist(TICKET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMWriteTicket(const char* data, uint32_t len)
|
||||
{
|
||||
printf("OEMWriteTicket data=%s -- len=%d\r\n",data,len);
|
||||
if(data == NULL || len == 0)
|
||||
return -1;
|
||||
|
||||
return WriteFile(TICKET_FILE_NAME,data,len,O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS);
|
||||
}
|
||||
|
||||
int32_t OEMReadTicket(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
printf("OEMReadTicket buffer=%s -- bufferLen=%d\r\n",buffer,bufferLen);
|
||||
if(buffer == NULL || bufferLen == 0)
|
||||
return -1;
|
||||
|
||||
return ReadFile(TICKET_FILE_NAME,buffer,bufferLen);
|
||||
}
|
||||
|
||||
int32_t OEMDeleteTicket(void)
|
||||
{
|
||||
return DeleteFile(TICKET_FILE_NAME);
|
||||
}
|
||||
|
||||
int32_t OEMGetTicketFileSize(uint32_t* len)
|
||||
{
|
||||
return UtilsFileStat(TICKET_FILE_NAME,len);
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
static_library("hal_sysparam") {
|
||||
sources = [ "hal_sys_param.c" ]
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
defines = [
|
||||
"INCREMENTAL_VERSION=\"${ohos_version}\"",
|
||||
"BUILD_TYPE=\"${ohos_build_type}\"",
|
||||
"BUILD_USER=\"${ohos_build_user}\"",
|
||||
"BUILD_TIME=\"${ohos_build_time}\"",
|
||||
"BUILD_HOST=\"${ohos_build_host}\"",
|
||||
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
|
||||
]
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
#include "hal_sys_param.h"
|
||||
|
||||
|
||||
#define PRD_Lamp_2HSB 1 /* DALEN product wifi+BLE +KIT */
|
||||
#define PRD_Lamp_2IES 2 /* DALEN product wifi+BLE +KIT */
|
||||
|
||||
|
||||
#define USING_PRODUCT_ID PRD_Lamp_2HSB
|
||||
|
||||
#if(USING_PRODUCT_ID == PRD_Lamp_2HSB)
|
||||
static const char OHOS_DEVICE_TYPE[] = {"Table Lamp"};
|
||||
static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
|
||||
static const char OHOS_MANUFACTURE[] = {"BEKEN"};
|
||||
static const char OHOS_BRAND[] = {"BEKEN"};
|
||||
static const char OHOS_MARKET_NAME[] = {"BK7231M-LIGHT"};
|
||||
static const char OHOS_PRODUCT_SERIES[] = {"light"};
|
||||
static const char OHOS_PRODUCT_MODEL[] = {"light-01"};
|
||||
static const char OHOS_SOFTWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"wifi:true,ble:true"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const char OHOS_ABI_LIST[] = {"riscv-liteos"};
|
||||
//static const char OHOS_SERIAL[] = {"C86000000001"};
|
||||
char OHOS_SERIAL[16] = {0};
|
||||
#elif(USING_PRODUCT_ID == PRD_Lamp_2IES)
|
||||
static const char OHOS_DEVICE_TYPE[] = {"Table Lamp"};
|
||||
static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
|
||||
static const char OHOS_MANUFACTURE[] = {"BEKEN"};
|
||||
static const char OHOS_BRAND[] = {"BEKEN"};
|
||||
static const char OHOS_MARKET_NAME[] = {"BK7235-LIGHT"};
|
||||
static const char OHOS_PRODUCT_SERIES[] = {"bk7235"};
|
||||
static const char OHOS_PRODUCT_MODEL[] = {"bk7235-002"};
|
||||
static const char OHOS_SOFTWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"1.0.0"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"wifi:true,ble:true"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const char OHOS_ABI_LIST[] = {"riscv-liteos"};
|
||||
|
||||
//static const char OHOS_SERIAL[] = {"123456789"};
|
||||
char OHOS_SERIAL[16] = {0};
|
||||
|
||||
#endif
|
||||
static const int OHOS_FIRST_API_VERSION = 1;
|
||||
|
||||
const char* HalGetDeviceType(void)
|
||||
{
|
||||
return OHOS_DEVICE_TYPE;
|
||||
}
|
||||
|
||||
const char* HalGetManufacture(void)
|
||||
{
|
||||
return OHOS_MANUFACTURE;
|
||||
}
|
||||
|
||||
const char* HalGetBrand(void)
|
||||
{
|
||||
return OHOS_BRAND;
|
||||
}
|
||||
|
||||
const char* HalGetMarketName(void)
|
||||
{
|
||||
return OHOS_MARKET_NAME;
|
||||
}
|
||||
|
||||
const char* HalGetProductSeries(void)
|
||||
{
|
||||
return OHOS_PRODUCT_SERIES;
|
||||
}
|
||||
|
||||
const char* HalGetProductModel(void)
|
||||
{
|
||||
return OHOS_PRODUCT_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetSoftwareModel(void)
|
||||
{
|
||||
return OHOS_SOFTWARE_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetHardwareModel(void)
|
||||
{
|
||||
return OHOS_HARDWARE_MODEL;
|
||||
}
|
||||
|
||||
const char* HalGetHardwareProfile(void)
|
||||
{
|
||||
return OHOS_HARDWARE_PROFILE;
|
||||
}
|
||||
char make_ohos_serial[16] = {0};
|
||||
#define in_range(c, lo, up) ((unsigned char)c >= lo && (unsigned char)c <= up)
|
||||
#define islower(c) in_range(c, 'a', 'z')
|
||||
#include "string.h"
|
||||
const char* HalGetSerial(void)
|
||||
{
|
||||
#if 1
|
||||
typedef int bk_err_t; /**< Return error code */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char mac_type_t;
|
||||
uint8_t mac_read[6];
|
||||
|
||||
extern bk_err_t bk_get_mac(uint8_t *mac, mac_type_t type);
|
||||
bk_get_mac(mac_read,0);
|
||||
os_snprintf(&make_ohos_serial[0],sizeof(make_ohos_serial),"%02x%02x%02x%02x%02x%02x",mac_read[0],mac_read[1],mac_read[2],mac_read[3],mac_read[4],mac_read[5]);
|
||||
|
||||
for(int i = 0; i<sizeof(make_ohos_serial);i++)
|
||||
{
|
||||
if(islower(make_ohos_serial[i]))
|
||||
make_ohos_serial[i] +='A' - 'a';
|
||||
}
|
||||
memcpy(OHOS_SERIAL,make_ohos_serial,strlen(make_ohos_serial)+1);
|
||||
#endif
|
||||
printf("OHOS_SERIAL=%s\r\n",OHOS_SERIAL);
|
||||
return OHOS_SERIAL;
|
||||
}
|
||||
|
||||
const char* HalGetBootloaderVersion(void)
|
||||
{
|
||||
return OHOS_BOOTLOADER_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetAbiList(void)
|
||||
{
|
||||
return OHOS_ABI_LIST;
|
||||
}
|
||||
|
||||
const char* HalGetDisplayVersion(void)
|
||||
{
|
||||
return OHOS_DISPLAY_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetIncrementalVersion(void)
|
||||
{
|
||||
return INCREMENTAL_VERSION;
|
||||
}
|
||||
|
||||
const char* HalGetBuildType(void)
|
||||
{
|
||||
return BUILD_TYPE;
|
||||
}
|
||||
|
||||
const char* HalGetBuildUser(void)
|
||||
{
|
||||
return BUILD_USER;
|
||||
}
|
||||
|
||||
const char* HalGetBuildHost(void)
|
||||
{
|
||||
return BUILD_HOST;
|
||||
}
|
||||
|
||||
const char* HalGetBuildTime(void)
|
||||
{
|
||||
return BUILD_TIME;
|
||||
}
|
||||
|
||||
int HalGetFirstApiVersion(void)
|
||||
{
|
||||
return OHOS_FIRST_API_VERSION;
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
const.build.characteristics=****
|
||||
|
||||
const.product.manufacturer=****
|
||||
|
||||
const.product.brand=****
|
||||
|
||||
const.product.name=****
|
||||
|
||||
const.build.product=****
|
||||
|
||||
const.product.model=****
|
||||
|
||||
const.software.model=****
|
||||
|
||||
const.product.hardwareversion=****
|
||||
|
||||
const.product.hardwareprofile="aout:true,display:true"
|
||||
|
||||
const.ohos.serial=1234567890
|
||||
|
||||
const.product.bootloader.version=bootloader
|
||||
|
||||
const.product.cpu.abilist=****
|
||||
|
||||
const.product.software.version="OpenHarmony 1.0.1"
|
||||
|
||||
const.product.firstapiversion=1
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
# Copyright (c) 2020 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.
|
||||
import("${board_adapter_dir}/hals/sdk_dir.gni")
|
||||
|
||||
static_library("hal_token_static") {
|
||||
sources = [ "hal_token.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
"${beken_sdk_dir}/include",
|
||||
"${beken_sdk_dir}/include/arch/compiler",
|
||||
"${beken_sdk_dir}/components/bk_cli/include",
|
||||
"${beken_sdk_dir}/components/bk_cli/include/bk_private",
|
||||
"//utils/native/lite/hals/file",
|
||||
"//applications/iot_solution/thing_model/WiFi",
|
||||
|
||||
]
|
||||
include_dirs += bk_hal_include_dirs
|
||||
|
||||
deps = []
|
||||
}
|
||||
Executable
+352
@@ -0,0 +1,352 @@
|
||||
#include "hal_token.h"
|
||||
#include "bk_cli.h"
|
||||
#include "ohos_errno.h"
|
||||
#include "ohos_types.h"
|
||||
#include "utils_file.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "hal_file.h"
|
||||
#include <securec.h>
|
||||
#include "iot_device.h"
|
||||
|
||||
|
||||
#define TokenPathA "/usrdata/hilink/tokenA.cfg"
|
||||
#define TokenPathB "/usrdata/hilink/tokenB.cfg"
|
||||
#define TOKEN_SIZE 151
|
||||
#define BITS_PER_BYTE 8
|
||||
// 4 Bytes for token flag
|
||||
// if token's both area are available, when read token, always return area which flag is bigger;
|
||||
// and recover area which flag is small while write token.
|
||||
#define TOKEN_FLAG_SIZE 4
|
||||
#define TOKEN_WITH_FLAG_SIZE (TOKEN_SIZE + TOKEN_FLAG_SIZE)
|
||||
|
||||
#define tokenstring "Y1DjGH2dzole/ZXcWPSBj1aysCNBqJ633C2AJPG0tHliEktcHys3WW15F/fSLEcP,kf+TmQyFh43H7loKz80Zz8Avog6xA+u3hM47Qcm2UicQ5GrHNRNBbnhxxYm8Q7Ve,n0yQTslNQFsnvrM3,0000"
|
||||
|
||||
static uint32_t GetTokenFlag(const char tokenWithFlag[])
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for (uint32_t i = 0; i < TOKEN_FLAG_SIZE; i++) {
|
||||
result |= ((uint8_t)tokenWithFlag[TOKEN_SIZE + i]) << ((TOKEN_FLAG_SIZE - 1 - i) * BITS_PER_BYTE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void SetTokenFlag(uint8_t flag[], uint32_t value)
|
||||
{
|
||||
for (uint32_t i = 0; i < TOKEN_FLAG_SIZE; i++) {
|
||||
flag[i] = (value >> (BITS_PER_BYTE * (TOKEN_FLAG_SIZE - 1 - i))) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int OEMReadToken(char *token, unsigned int len)
|
||||
{
|
||||
int tokenAfd,tokenBfd;
|
||||
int tokenReadLen;
|
||||
(void) tokenReadLen;
|
||||
tokenAfd = HalFileOpen(TokenPathA , O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
if((tokenAfd < 0)&&(tokenBfd < 0)){
|
||||
memcpy((char *)token, (char *)tokenstring, len);
|
||||
return EC_SUCCESS;//-2;
|
||||
|
||||
}else if((tokenAfd >= 0)&&(tokenBfd < 0)){
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenReadLen = HalFileRead(tokenAfd,token,len);
|
||||
HalFileClose(tokenAfd);
|
||||
return EC_SUCCESS;
|
||||
|
||||
}else if((tokenAfd < 0)&&(tokenBfd >= 0)){
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenReadLen = HalFileRead(tokenBfd,token,len);
|
||||
HalFileClose(tokenBfd);
|
||||
return EC_SUCCESS;
|
||||
|
||||
}else if((tokenAfd >= 0)&&(tokenBfd >= 0)){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenReadLen = HalFileRead(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
tokenReadLen = HalFileRead(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
uint32_t flagA = GetTokenFlag(tokenA_withFlag);
|
||||
uint32_t flagB = GetTokenFlag(tokenB_withFlag);
|
||||
if(flagA >= flagB){
|
||||
(void)memcpy_s(token, len, tokenA_withFlag, len);
|
||||
}else{
|
||||
(void)memcpy_s(token, len, tokenB_withFlag, len);
|
||||
}
|
||||
free(tokenA_withFlag);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
HalFileClose(tokenBfd);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int OEMWriteToken(const char *token, unsigned int len)
|
||||
{
|
||||
int tokenAfd,tokenBfd;
|
||||
int tokenAfileSize,tokenBfileSize;
|
||||
int tokenWriteLen;
|
||||
(void )tokenWriteLen;
|
||||
uint32_t flagA,flagB;
|
||||
|
||||
tokenAfileSize = FileSize(TokenPathA );
|
||||
tokenBfileSize = FileSize(TokenPathB);
|
||||
|
||||
if((tokenAfileSize <= 0)&&(tokenBfileSize <= 0)){
|
||||
//no A,no B. creat A
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_CREAT_FS|O_RDWR_FS, 0);
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],1);
|
||||
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenA_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
}
|
||||
|
||||
}else if((tokenAfileSize > 0)&&(tokenBfileSize <= 0)){
|
||||
//only A. creat B
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_CREAT_FS|O_RDWR_FS, 0);
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagA = GetTokenFlag(tokenA_withFlag);
|
||||
free(tokenA_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
}else{
|
||||
flagA = 0;
|
||||
}
|
||||
|
||||
flagB = flagA + 1;
|
||||
|
||||
if(tokenBfd>=0){
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenB_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
tokenWriteLen = HalFileWrite(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenBfd);
|
||||
}
|
||||
|
||||
}else if((tokenAfileSize <= 0)&&(tokenBfileSize > 0)){
|
||||
//only B.creat A
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_CREAT_FS|O_RDWR_FS, 0);
|
||||
if(tokenBfd>=0){
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagB = GetTokenFlag(tokenB_withFlag);
|
||||
free(tokenB_withFlag);
|
||||
HalFileClose(tokenBfd);
|
||||
}else{
|
||||
flagB = 0;
|
||||
}
|
||||
|
||||
flagA = flagB + 1;
|
||||
|
||||
if(tokenAfd>=0){
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
free(tokenA_withFlag);
|
||||
HalFileClose(tokenAfd);
|
||||
}
|
||||
|
||||
}else if((tokenAfileSize > 0)&&(tokenBfileSize > 0)){
|
||||
tokenAfd = HalFileOpen(TokenPathA, O_RDWR_FS, 0);
|
||||
tokenBfd = HalFileOpen(TokenPathB, O_RDWR_FS, 0);
|
||||
char *tokenA_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
char *tokenB_withFlag = malloc(TOKEN_WITH_FLAG_SIZE);
|
||||
//get flagA,flagB
|
||||
if(tokenAfd>=0){
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagA = GetTokenFlag(tokenA_withFlag);
|
||||
}else{
|
||||
flagA = 0;
|
||||
}
|
||||
|
||||
if(tokenBfd>=0){
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
HalFileRead(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
flagB = GetTokenFlag(tokenB_withFlag);
|
||||
}else{
|
||||
flagB = 0;
|
||||
}
|
||||
//write file
|
||||
if(flagA <= flagB){
|
||||
if(tokenAfd>=0){
|
||||
flagA = flagB + 1;
|
||||
(void)memcpy_s(tokenA_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenA_withFlag[TOKEN_SIZE],flagA);
|
||||
HalFileSeek(tokenAfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenAfd,tokenA_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
}
|
||||
}else{
|
||||
if(tokenBfd>=0){
|
||||
flagB = flagA + 1;
|
||||
(void)memcpy_s(tokenB_withFlag, len, token, len);
|
||||
SetTokenFlag((uint8_t *)&tokenB_withFlag[TOKEN_SIZE],flagB);
|
||||
HalFileSeek(tokenBfd, 0, SEEK_SET_FS);
|
||||
tokenWriteLen = HalFileWrite(tokenBfd,tokenB_withFlag,TOKEN_WITH_FLAG_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
//close file
|
||||
if(tokenAfd>=0) HalFileClose(tokenAfd);
|
||||
if(tokenBfd>=0) HalFileClose(tokenBfd);
|
||||
free(tokenA_withFlag);
|
||||
free(tokenB_withFlag);
|
||||
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int OEMGetAcKey(char *acKey, unsigned int len)
|
||||
{
|
||||
extern unsigned char A_C[48];
|
||||
memcpy(acKey,A_C,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int OEMGetProdId(char *productId, unsigned int len)
|
||||
{
|
||||
memcpy(productId,PRODUCT_ID,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
//c35d6777954b439aaf2da4a1e3b1fe61
|
||||
static int OEMGetProdKey(char *productKey, unsigned int len)
|
||||
{
|
||||
memcpy(productKey,PRODUCT_KEY,len);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int HalReadToken(char *token, unsigned int len)
|
||||
{
|
||||
if (token == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMReadToken(token, len);
|
||||
}
|
||||
|
||||
int HalWriteToken(const char *token, unsigned int len)
|
||||
{
|
||||
if ((token == NULL) ||(len==0)){
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMWriteToken(token, len);
|
||||
}
|
||||
|
||||
int HalGetAcKey(char *acKey, unsigned int len)
|
||||
{
|
||||
if (acKey == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMGetAcKey(acKey, len);
|
||||
}
|
||||
|
||||
int HalGetProdId(char *productId, unsigned int len)
|
||||
{
|
||||
if (productId == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMGetProdId(productId, len);
|
||||
}
|
||||
|
||||
int HalGetProdKey(char *productKey, unsigned int len)
|
||||
{
|
||||
if (productKey == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
return OEMGetProdKey(productKey, len);
|
||||
}
|
||||
|
||||
void token_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
|
||||
{
|
||||
static char *tokenbuf;
|
||||
static uint8 token_pos = 0;
|
||||
if (argc >= 1)
|
||||
{
|
||||
if (os_strcmp(argv[1], "w") == 0){
|
||||
if (os_strcmp(argv[2], "part1") == 0){
|
||||
if(strlen(argv[3]) <= TOKEN_SIZE){
|
||||
if(tokenbuf == NULL){
|
||||
tokenbuf = (char *)malloc(TOKEN_SIZE+1);
|
||||
}
|
||||
(void)memcpy_s(tokenbuf, TOKEN_SIZE, argv[3], strlen(argv[3]));
|
||||
token_pos = strlen(argv[3]);
|
||||
}else{
|
||||
printf("token part1 len valid.should <= 151\r\n");
|
||||
}
|
||||
}else if (os_strcmp(argv[2], "part2") == 0){
|
||||
if(tokenbuf == NULL){
|
||||
printf("token buff if NULL.should write part1 first!\r\n");
|
||||
}else{
|
||||
(void)memcpy_s(&tokenbuf[token_pos], TOKEN_SIZE, argv[3], strlen(argv[3]));
|
||||
printf("token len : %d = %d + %d. : %s\r\n",token_pos+strlen(argv[3]), token_pos,strlen(argv[3]),tokenbuf);
|
||||
if((token_pos+strlen(argv[3]))==TOKEN_SIZE){
|
||||
HalWriteToken(tokenbuf,TOKEN_SIZE);
|
||||
}else{
|
||||
printf("token len valid.part1+part2 should be 151\r\n");
|
||||
}
|
||||
free(tokenbuf);
|
||||
}
|
||||
|
||||
}else if (os_strcmp(argv[2], "local") == 0){
|
||||
HalWriteToken(tokenstring,sizeof(tokenstring));
|
||||
}else{
|
||||
printf("str len:%d\r\n",strlen(argv[2]));
|
||||
if(strlen(argv[2])==TOKEN_SIZE){
|
||||
HalWriteToken(argv[2],TOKEN_SIZE);
|
||||
}
|
||||
}
|
||||
}else if(os_strcmp(argv[1], "r") == 0){
|
||||
char *tokenRbuf = (char *)malloc(TOKEN_SIZE+1);
|
||||
HalReadToken(tokenRbuf,TOKEN_SIZE);
|
||||
char tmp_c;
|
||||
tmp_c = tokenRbuf[80];
|
||||
tokenRbuf[80] = '\0';
|
||||
printf("tokenbuf =%s",tokenRbuf); //printf part1
|
||||
tokenRbuf[80] = tmp_c;
|
||||
tokenRbuf[151] = '\0';
|
||||
printf("%s\r\n",&tokenRbuf[80]); //printf part2
|
||||
free(tokenRbuf);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const struct cli_command token_clis[] = {
|
||||
|
||||
{"token", "token w/r ", token_command},
|
||||
|
||||
};
|
||||
|
||||
void bk_token_cli_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bk_printf("token cli int \r\n");
|
||||
ret = cli_register_commands(token_clis, sizeof(token_clis) / sizeof(struct cli_command));
|
||||
if (ret)
|
||||
bk_printf("ret: %d token commands fail.\r\n",ret);
|
||||
}
|
||||
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
# LOSCFG_COMPILE_OPTIMIZE is not set
|
||||
# LOSCFG_COMPILE_LTO is not set
|
||||
LOSCFG_PLATFORM_QEMU_RISCV32_VIRT=y
|
||||
LOSCFG_SOC_SERIES_BK7235=y
|
||||
# LOSCFG_POSIX_SEM_API is not set
|
||||
# LOSCFG_POSIX_MQUEUE_API is not set
|
||||
# LOSCFG_POSIX_PIPE_API is not set
|
||||
# LOSCFG_POSIX_SIGNAL_API is not set
|
||||
# LOSCFG_FS_VFS is not set
|
||||
# LOSCFG_PLATFORM_ADAPT is not set
|
||||
# LOSCFG_ENABLE_MAGICKEY is not set
|
||||
# LOSCFG_DEBUG_VERSION is not set
|
||||
LOSCFG_DRIVERS_HDF=y
|
||||
LOSCFG_DRIVERS_HDF_PLATFORM=y
|
||||
LOSCFG_CC_NO_STACKPROTECTOR=y
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"parts": {
|
||||
"product_test_xts_part1": {
|
||||
"module_list": [
|
||||
"//vendor/beken/test_xts_part1:test_xts_part1"
|
||||
]
|
||||
}
|
||||
},
|
||||
"subsystem": "product_test_xts_part1"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
group("wifi_iot") {
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
{
|
||||
"product_name": "wifi_iot",
|
||||
"ohos_version": "OpenHarmony 1.0",
|
||||
"device_company": "bk_corp",
|
||||
"board": "bk7231",
|
||||
"kernel_type": "liteos_m",
|
||||
"kernel_version": "0.2.x.n",
|
||||
"subsystems": [
|
||||
{
|
||||
"subsystem": "iot_hardware",
|
||||
"components": [
|
||||
{ "component": "iot_controller", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "communication",
|
||||
"components": [
|
||||
{ "component": "wlan", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "distributed_schedule",
|
||||
"components": [
|
||||
{ "component": "system_ability_manager", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "startup",
|
||||
"components": [
|
||||
{ "component": "syspara", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "utils",
|
||||
"components": [
|
||||
{ "component": "kv_store", "features":[] },
|
||||
{ "component": "file", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "beken",
|
||||
"components": [
|
||||
{ "component": "ohos_entry", "features":[] },
|
||||
{ "component": "bk7231_sdk", "features":[] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"subsystem": "security",
|
||||
"components": [
|
||||
{ "component": "hichainsdk", "features":[] },
|
||||
{ "component": "huks", "features":[
|
||||
"disable_huks_binary = true",
|
||||
"disable_authenticate = true"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"vendor_adapter_dir": "//device/bk_corp/bk7231",
|
||||
"third_party_dir": "//device/bk_corp/bk7231/bk7231_sdk/third_party",
|
||||
"product_adapter_dir": "//vendor/beken/wifi_iot/hals",
|
||||
"ohos_product_type":"",
|
||||
"ohos_manufacture":"",
|
||||
"ohos_brand":"",
|
||||
"ohos_market_name":"",
|
||||
"ohos_product_series":"",
|
||||
"ohos_product_model":"",
|
||||
"ohos_software_model":"",
|
||||
"ohos_hardware_model":"",
|
||||
"ohos_hardware_profile":"",
|
||||
"ohos_serial":"",
|
||||
"ohos_bootloader_version":"",
|
||||
"ohos_secure_patch_level":"",
|
||||
"ohos_abi_list":""
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
static_library("hal_sysparam") {
|
||||
sources = [ "hal_sys_param.c" ]
|
||||
include_dirs = [
|
||||
"//base/startup/syspara_lite/hals",
|
||||
"//utils/native/lite/include",
|
||||
"//foundation/hilink/include",
|
||||
]
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
#include "hal_sys_param.h"
|
||||
#include <securec.h>
|
||||
#include "hilink_device.h"
|
||||
|
||||
|
||||
char* HalGetProductType(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_PRODUCT_TYPE) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_PRODUCT_TYPE) + 1, OHOS_PRODUCT_TYPE) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetManufacture(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(MANUAFACTURER_NAME) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(MANUAFACTURER_NAME) + 1, MANUAFACTURER_NAME) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetBrand(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_BRAND) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_BRAND) + 1, OHOS_BRAND) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetMarketName(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_MARKET_NAME) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_MARKET_NAME) + 1, OHOS_MARKET_NAME) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetProductSeries(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_PRODUCT_SERIES) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_PRODUCT_SERIES) + 1, OHOS_PRODUCT_SERIES) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetProductModel(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(PRODUCT_MODEL) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(PRODUCT_MODEL) + 1, PRODUCT_MODEL) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetSoftwareModel(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(SOFTWARE_VER) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(SOFTWARE_VER) + 1, SOFTWARE_VER) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetHardwareModel(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(HARDWARE_VER) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(HARDWARE_VER) + 1, HARDWARE_VER) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetHardwareProfile(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_HARDWARE_PROFILE) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_HARDWARE_PROFILE) + 1, OHOS_HARDWARE_PROFILE) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetSerial(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_SERIAL) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_SERIAL) + 1, OHOS_SERIAL) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetBootloaderVersion(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_BOOTLOADER_VERSION) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_BOOTLOADER_VERSION) + 1, OHOS_BOOTLOADER_VERSION) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetSecurityPatchTag(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_SECURITY_PATCH_TAG) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_SECURITY_PATCH_TAG) + 1, OHOS_SECURITY_PATCH_TAG) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
char* HalGetAbiList(void)
|
||||
{
|
||||
char* value = (char*)malloc(strlen(OHOS_ABI_LIST) + 1);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(value, strlen(OHOS_ABI_LIST) + 1, OHOS_ABI_LIST) != 0) {
|
||||
free(value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
. :
|
||||
- vendor/beken/wifi_iot/patches/bounds_checking_function.patch
|
||||
- vendor/beken/wifi_iot/patches/cmsis.patch
|
||||
- vendor/beken/wifi_iot/patches/mbedtls.patch
|
||||
- vendor/beken/wifi_iot/patches/musl.patch
|
||||
- vendor/beken/wifi_iot/patches/cJSON.patch
|
||||
- vendor/beken/wifi_iot/patches/base.patch
|
||||
- vendor/beken/wifi_iot/patches/build.patch
|
||||
- vendor/beken/wifi_iot/patches/foundation.patch
|
||||
- vendor/beken/wifi_iot/patches/test.patch
|
||||
- vendor/beken/wifi_iot/patches/utils.patch
|
||||
- vendor/beken/wifi_iot/patches/kernel.patch
|
||||
File diff suppressed because one or more lines are too long
@@ -1,26 +0,0 @@
|
||||
diff --git a/third_party/bounds_checking_function/.gitignore b/third_party/bounds_checking_function/.gitignore
|
||||
deleted file mode 100644
|
||||
index 5761abcf..00000000
|
||||
--- a/third_party/bounds_checking_function/.gitignore
|
||||
+++ /dev/null
|
||||
@@ -1 +0,0 @@
|
||||
-*.o
|
||||
diff --git a/third_party/bounds_checking_function/BUILD.gn b/third_party/bounds_checking_function/BUILD.gn
|
||||
index 09f527b1..8dc638bf 100755
|
||||
--- a/third_party/bounds_checking_function/BUILD.gn
|
||||
+++ b/third_party/bounds_checking_function/BUILD.gn
|
||||
@@ -65,10 +65,13 @@ libsec_sources = [
|
||||
"//third_party/bounds_checking_function/src/wscanf_s.c",
|
||||
]
|
||||
|
||||
+libsec_sources_dummy = [
|
||||
+]
|
||||
+
|
||||
if (defined(ohos_lite)) {
|
||||
lite_library("libsec_static") {
|
||||
target_type = "static_library"
|
||||
- sources = libsec_sources
|
||||
+ sources = libsec_sources_dummy
|
||||
public_configs = [ ":libsec_public_config" ]
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
diff --git a/build/lite/components/beken.json b/build/lite/components/beken.json
|
||||
new file mode 100755
|
||||
index 00000000..ed16902e
|
||||
--- /dev/null
|
||||
+++ b/build/lite/components/beken.json
|
||||
@@ -0,0 +1,46 @@
|
||||
+{
|
||||
+ "components": [
|
||||
+ {
|
||||
+ "component": "ohos_entry",
|
||||
+ "description": "my ohos entry.",
|
||||
+ "optional": "true",
|
||||
+ "dirs": [
|
||||
+ "//device/bk_corp/bk7231/bk7231_sdk/ohos_entry"
|
||||
+ ],
|
||||
+ "targets": [
|
||||
+ "//device/bk_corp/bk7231/bk7231_sdk/ohos_entry:ohos_entry"
|
||||
+ ],
|
||||
+ "rom": "",
|
||||
+ "ram": "",
|
||||
+ "output": [],
|
||||
+ "adapted_kernel": [ "liteos_m" ],
|
||||
+ "features": [],
|
||||
+ "deps": {
|
||||
+ "components": [],
|
||||
+ "third_party": [ ]
|
||||
+ }
|
||||
+ },
|
||||
+ {
|
||||
+ "component": "bk7231_sdk",
|
||||
+ "description": "",
|
||||
+ "optional": "false",
|
||||
+ "dirs": [
|
||||
+ "device/bk_corp/bk7231/bk7231_sdk"
|
||||
+ ],
|
||||
+ "targets": [
|
||||
+ "//device/bk_corp/bk7231/bk7231_sdk:bk_sdk"
|
||||
+ ],
|
||||
+ "rom": "",
|
||||
+ "ram": "",
|
||||
+ "output": [],
|
||||
+ "adapted_board": [],
|
||||
+ "adapted_kernel": [ "liteos_m" ],
|
||||
+ "features": [],
|
||||
+ "deps": {
|
||||
+ "components": [
|
||||
+ "utils_base"
|
||||
+ ]
|
||||
+ }
|
||||
+ }
|
||||
+ ]
|
||||
+}
|
||||
diff --git a/build/lite/components/security.json b/build/lite/components/security.json
|
||||
index af049a1c..3bc6c264 100755
|
||||
--- a/build/lite/components/security.json
|
||||
+++ b/build/lite/components/security.json
|
||||
@@ -68,6 +68,7 @@
|
||||
"output": [ "libhuks.so" ],
|
||||
"adapted_kernel": [
|
||||
"liteos_a",
|
||||
+ "liteos_m",
|
||||
"linux"
|
||||
],
|
||||
"features": [],
|
||||
@@ -1,302 +0,0 @@
|
||||
diff --git a/third_party/cJSON/.editorconfig b/third_party/cJSON/.editorconfig
|
||||
deleted file mode 100644
|
||||
index befb2c20..00000000
|
||||
--- a/third_party/cJSON/.editorconfig
|
||||
+++ /dev/null
|
||||
@@ -1,23 +0,0 @@
|
||||
-root = true
|
||||
-
|
||||
-
|
||||
-[*]
|
||||
-indent_style = space
|
||||
-indent_size = 4
|
||||
-end_of_line = lf
|
||||
-charset = utf-8
|
||||
-trim_trailing_whitespace = true
|
||||
-insert_final_newline = true
|
||||
-
|
||||
-[Makefile]
|
||||
-indent_style = tab
|
||||
-indent_size = unset
|
||||
-
|
||||
-# ignore external repositories and test inputs
|
||||
-[tests/{unity,json-patch-tests,inputs}/*]
|
||||
-indent_style = unset
|
||||
-indent_size = unset
|
||||
-end_of_line = unset
|
||||
-charset = unset
|
||||
-trim_trailing_whitespace = unset
|
||||
-insert_final_newline = unset
|
||||
diff --git a/third_party/cJSON/.gitattributes b/third_party/cJSON/.gitattributes
|
||||
deleted file mode 100644
|
||||
index 7491fcc7..00000000
|
||||
--- a/third_party/cJSON/.gitattributes
|
||||
+++ /dev/null
|
||||
@@ -1,8 +0,0 @@
|
||||
-* text=auto
|
||||
-/tests/inputs/* text eol=lf
|
||||
-
|
||||
-.gitattributes export-ignore
|
||||
-.gitignore export-ignore
|
||||
-.github export-ignore
|
||||
-.editorconfig export-ignore
|
||||
-.travis.yml export-ignore
|
||||
diff --git a/third_party/cJSON/.github/CONTRIBUTING.md b/third_party/cJSON/.github/CONTRIBUTING.md
|
||||
deleted file mode 100644
|
||||
index 83d2e599..00000000
|
||||
--- a/third_party/cJSON/.github/CONTRIBUTING.md
|
||||
+++ /dev/null
|
||||
@@ -1,54 +0,0 @@
|
||||
-Contribution Guidelines
|
||||
-=======================
|
||||
-
|
||||
-Contributions to cJSON are welcome. If you find a bug or want to improve cJSON in another way, pull requests are appreciated.
|
||||
-
|
||||
-For bigger changes, in order to avoid wasted effort, please open an issue to discuss the technical details before creating a pull request.
|
||||
-
|
||||
-The further sections explain the process in more detail and provides some guidelines on how contributions should look like.
|
||||
-
|
||||
-Branches
|
||||
---------
|
||||
-There are two branches to be aware of, the `master` and the `develop` branch. The `master` branch is reserved for the latest release, so only make pull requests to the `master` branch for small bug- or security fixes (these are usually just a few lines). In all other cases, please make a pull request to the `develop` branch.
|
||||
-
|
||||
-Coding Style
|
||||
-------------
|
||||
-The coding style has been discussed in [#24](https://github.com/DaveGamble/cJSON/issues/24). The basics are:
|
||||
-
|
||||
-* Use 4 spaces for indentation
|
||||
-* No oneliners (conditions, loops, variable declarations ...)
|
||||
-* Always use parenthesis for control structures
|
||||
-* Don't implicitly rely on operator precedence, use round brackets in expressions. e.g. `(a > b) && (c < d)` instead of `a>b && c<d`
|
||||
-* opening curly braces start in the next line
|
||||
-* use spaces around operators
|
||||
-* lines should not have trailing whitespace
|
||||
-* use spaces between function parameters
|
||||
-* use pronouncable variable names, not just a combination of letters
|
||||
-
|
||||
-Example:
|
||||
-
|
||||
-```c
|
||||
-/* calculate the new length of the string in a printbuffer and update the offset */
|
||||
-static void update_offset(printbuffer * const buffer)
|
||||
-{
|
||||
- const unsigned char *buffer_pointer = NULL;
|
||||
- if ((buffer == NULL) || (buffer->buffer == NULL))
|
||||
- {
|
||||
- return;
|
||||
- }
|
||||
- buffer_pointer = buffer->buffer + buffer->offset;
|
||||
-
|
||||
- buffer->offset += strlen((const char*)buffer_pointer);
|
||||
-}
|
||||
-```
|
||||
-
|
||||
-Unit Tests
|
||||
-----------
|
||||
-cJSON uses the [Unity](https://github.com/ThrowTheSwitch/Unity) library for unit tests. The tests are located in the `tests` directory. In order to add a new test, either add it to one of the existing files (if it fits) or add a new C file for the test. That new file has to be added to the list of tests in `tests/CMakeLists.txt`.
|
||||
-
|
||||
-All new features have to be covered by unit tests.
|
||||
-
|
||||
-Other Notes
|
||||
------------
|
||||
-* Internal functions are to be declared static.
|
||||
-* Wrap the return type of external function in the `CJSON_PUBLIC` macro.
|
||||
diff --git a/third_party/cJSON/.github/workflows/CI.yml b/third_party/cJSON/.github/workflows/CI.yml
|
||||
deleted file mode 100644
|
||||
index dc9d17c6..00000000
|
||||
--- a/third_party/cJSON/.github/workflows/CI.yml
|
||||
+++ /dev/null
|
||||
@@ -1,102 +0,0 @@
|
||||
-name: CI
|
||||
-
|
||||
-on:
|
||||
- push:
|
||||
- branches: [ master ]
|
||||
- paths-ignore:
|
||||
- - '**.md'
|
||||
- - 'LICENSE'
|
||||
- pull_request:
|
||||
- types: [opened, synchronize]
|
||||
- paths-ignore:
|
||||
- - '**.md'
|
||||
- - 'LICENSE'
|
||||
-
|
||||
-jobs:
|
||||
- linux:
|
||||
- runs-on: ubuntu-latest
|
||||
- if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
- strategy:
|
||||
- fail-fast: false
|
||||
- matrix:
|
||||
- mem_check:
|
||||
- - ENABLE_VALGRIND
|
||||
- - ENABLE_SANITIZERS
|
||||
- - NONE_MEM_CHECK
|
||||
- compiler:
|
||||
- - GCC
|
||||
- - CLANG
|
||||
- steps:
|
||||
- - uses: actions/checkout@v2
|
||||
- - name: install build dependencies
|
||||
- run: |
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install clang-8 valgrind
|
||||
- - name: build and test
|
||||
- shell: bash
|
||||
- run: |
|
||||
- if [ "${{ matrix.mem_check }}" == "ENABLE_VALGRIND" ]; then
|
||||
- EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=ON -DENABLE_SAFE_STACK=ON -DENABLE_SANITIZERS=OFF"
|
||||
- elif [ "${{ matrix.mem_check }}" == "ENABLE_SANITIZERS" ]; then
|
||||
- EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=ON"
|
||||
- else
|
||||
- EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=OFF"
|
||||
- fi
|
||||
- if [ "${{ matrix.compiler }}" == "GCC" ]; then
|
||||
- export CC=gcc
|
||||
- else
|
||||
- export CC=clang
|
||||
- fi
|
||||
- #run build and test
|
||||
- JOBS=20
|
||||
- export CTEST_PARALLEL_LEVEL=$JOBS
|
||||
- export CTEST_OUTPUT_ON_FAILURE=1
|
||||
- mkdir -p build
|
||||
- cd build
|
||||
- echo [cmake]: cmake .. $EVENT_CMAKE_OPTIONS
|
||||
- cmake .. $EVENT_CMAKE_OPTIONS || (rm -rf * && cmake .. $EVENT_CMAKE_OPTIONS)
|
||||
- cmake --build .
|
||||
- make
|
||||
- make test
|
||||
-
|
||||
- macos:
|
||||
- runs-on: macos-latest
|
||||
- if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
- strategy:
|
||||
- fail-fast: false
|
||||
- matrix:
|
||||
- mem_check:
|
||||
- - ENABLE_VALGRIND
|
||||
- - ENABLE_SANITIZERS
|
||||
- - NONE_MEM_CHECK
|
||||
- compiler:
|
||||
- - GCC
|
||||
- - CLANG
|
||||
- steps:
|
||||
- - uses: actions/checkout@v2
|
||||
- - name: build and test
|
||||
- shell: bash
|
||||
- run: |
|
||||
- if [ "${{ matrix.mem_check }}" == "ENABLE_VALGRIND" ]; then
|
||||
- EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=ON -DENABLE_SAFE_STACK=ON -DENABLE_SANITIZERS=OFF"
|
||||
- elif [ "${{ matrix.mem_check }}" == "ENABLE_SANITIZERS" ]; then
|
||||
- EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=ON"
|
||||
- else
|
||||
- EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=OFF"
|
||||
- fi
|
||||
- if [ "${{ matrix.compiler }}" == "GCC" ]; then
|
||||
- export CC=gcc
|
||||
- else
|
||||
- export CC=clang
|
||||
- fi
|
||||
- #run build and test
|
||||
- JOBS=20
|
||||
- export CTEST_PARALLEL_LEVEL=$JOBS
|
||||
- export CTEST_OUTPUT_ON_FAILURE=1
|
||||
- mkdir -p build
|
||||
- cd build
|
||||
- echo [cmake]: cmake .. $EVENT_CMAKE_OPTIONS
|
||||
- cmake .. $EVENT_CMAKE_OPTIONS || (rm -rf * && cmake .. $EVENT_CMAKE_OPTIONS)
|
||||
- cmake --build .
|
||||
- make
|
||||
- make test
|
||||
diff --git a/third_party/cJSON/.gitignore b/third_party/cJSON/.gitignore
|
||||
deleted file mode 100644
|
||||
index 58edf92c..00000000
|
||||
--- a/third_party/cJSON/.gitignore
|
||||
+++ /dev/null
|
||||
@@ -1,18 +0,0 @@
|
||||
-.svn
|
||||
-test
|
||||
-*.o
|
||||
-*.a
|
||||
-*.so
|
||||
-*.swp
|
||||
-*.patch
|
||||
-tags
|
||||
-*.dylib
|
||||
-build/
|
||||
-cJSON_test
|
||||
-cJSON_test_utils
|
||||
-libcjson.so.*
|
||||
-libcjson_utils.so.*
|
||||
-*.orig
|
||||
-.vscode
|
||||
-.idea
|
||||
-cmake-build-debug
|
||||
diff --git a/third_party/cJSON/.travis.yml b/third_party/cJSON/.travis.yml
|
||||
deleted file mode 100644
|
||||
index e7ff744e..00000000
|
||||
--- a/third_party/cJSON/.travis.yml
|
||||
+++ /dev/null
|
||||
@@ -1,28 +0,0 @@
|
||||
-dist: trusty
|
||||
-sudo: false
|
||||
-language: c
|
||||
-env:
|
||||
- matrix:
|
||||
- - VALGRIND=On SANITIZERS=Off
|
||||
- - VALGRIND=Off SANITIZERS=Off
|
||||
- - VALGRIND=Off SANITIZERS=On
|
||||
-compiler:
|
||||
- - gcc
|
||||
- - clang
|
||||
-addons:
|
||||
- apt:
|
||||
- packages:
|
||||
- - valgrind
|
||||
- - libasan0
|
||||
- - lib32asan0
|
||||
- # currently not supported on travis:
|
||||
- # - libasan1
|
||||
- # - libasan2
|
||||
- # - libubsan0
|
||||
- - llvm
|
||||
-script:
|
||||
- - mkdir build
|
||||
- - cd build
|
||||
- - cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SAFE_STACK="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}"
|
||||
- - make
|
||||
- - make test CTEST_OUTPUT_ON_FAILURE=On
|
||||
diff --git a/third_party/cJSON/Makefile b/third_party/cJSON/Makefile
|
||||
index b1432305..3f0db43b 100644
|
||||
--- a/third_party/cJSON/Makefile
|
||||
+++ b/third_party/cJSON/Makefile
|
||||
@@ -24,14 +24,17 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
|
||||
|
||||
INSTALL ?= cp -a
|
||||
|
||||
-CC = gcc -std=c89
|
||||
+#CC = gcc -std=c89
|
||||
+CC = arm-none-eabi-gcc -std=c89
|
||||
+AR = arm-none-eabi-ar
|
||||
|
||||
# validate gcc version for use fstack-protector-strong
|
||||
MIN_GCC_VERSION = "4.9"
|
||||
GCC_VERSION := "`$(CC) -dumpversion`"
|
||||
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
|
||||
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
|
||||
- CFLAGS += -fstack-protector-strong
|
||||
+ CFLAGS += -fno-stack-protector
|
||||
+ #-fstack-protector-strong
|
||||
else
|
||||
CFLAGS += -fstack-protector
|
||||
endif
|
||||
@@ -68,7 +71,7 @@ SHARED_CMD = $(CC) -shared -o
|
||||
|
||||
.PHONY: all shared static tests clean install
|
||||
|
||||
-all: shared static tests
|
||||
+all: shared static #tests
|
||||
|
||||
shared: $(CJSON_SHARED) $(UTILS_SHARED)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
||||
diff --git a/third_party/unity/.editorconfig b/third_party/unity/.editorconfig
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
diff --git a/third_party/unity/.gitattributes b/third_party/unity/.gitattributes
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
diff --git a/third_party/unity/.gitignore b/third_party/unity/.gitignore
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
diff --git a/third_party/unity/.travis.yml b/third_party/unity/.travis.yml
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
diff --git a/third_party/unity/test/.rubocop.yml b/third_party/unity/test/.rubocop.yml
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
@@ -1,24 +0,0 @@
|
||||
diff --git a/utils/native/lite/hals/file/hal_file.h b/utils/native/lite/hals/file/hal_file.h
|
||||
index bfcf3a29..bc5a94f7 100755
|
||||
--- a/utils/native/lite/hals/file/hal_file.h
|
||||
+++ b/utils/native/lite/hals/file/hal_file.h
|
||||
@@ -36,10 +36,17 @@ int HalFileStat(const char* path, unsigned int* fileSize);
|
||||
|
||||
int HalFileSeek(int fd, int offset, unsigned int whence);
|
||||
|
||||
+int FileRead(const char *filename, unsigned int offset, char *buf, unsigned int len);
|
||||
+
|
||||
+int FileWrite(const char *filename, unsigned int offset, const char *buf, unsigned int len);
|
||||
+
|
||||
+int FileSize(const char *filename);
|
||||
+
|
||||
+
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
-#endif // HAL_FILE_SYSTEM_API_H
|
||||
\ No newline at end of file
|
||||
+#endif // HAL_FILE_SYSTEM_API_H
|
||||
Reference in New Issue
Block a user