diff --git a/adapter/include/adapter_tls.h b/adapter/include/adapter_tls.h index aee2556076c4f8b07f472f3f14a38d5586b457a0..5b471c6567a2de45d8606f7904e27bee324c55d6 100644 --- a/adapter/include/adapter_tls.h +++ b/adapter/include/adapter_tls.h @@ -18,7 +18,7 @@ #include #include -#if __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -192,7 +192,7 @@ int32_t AdapterTlsClientSend(AdapterTlsClient *cli, const uint8_t *buf, uint32_t */ AdapterTlsCertVerify AdapterTlsClientVerifyCert(AdapterTlsClient *cli); -#if __cplusplus +#ifdef __cplusplus } #endif diff --git a/adapter/tls/mbedtls/adapter_tls.c b/adapter/tls/mbedtls/adapter_tls.c index 10262e50c0f811073276736ef9b7088f1375de7a..2f5cb6e12ab1788ee0c69308a06656c77d26da81 100644 --- a/adapter/tls/mbedtls/adapter_tls.c +++ b/adapter/tls/mbedtls/adapter_tls.c @@ -202,6 +202,7 @@ static int32_t InitTlsSocket(TlsClient *cli) ADAPTER_LOGW("sprintf error"); return IOTC_ERR_SECUREC_SPRINTF; } + ADAPTER_LOGW("hostName=%s,port=%u", cli->hostName, cli->port); ret = mbedtls_net_connect(&cli->fd, cli->hostName, portStr, MBEDTLS_NET_PROTO_TCP); if (ret != 0) { ADAPTER_LOGW("connect error [-0x%04x/%d]", -ret, AdapterGetErrno()); diff --git a/adapter/wifi/oh_lite/adapter_wifi.c b/adapter/wifi/oh_lite/adapter_wifi.c index 33dcf72543ef9a974c2b51fbb83a1eae879e4987..e60ed19dc079aaa170816b49b24c401cfe003f59 100644 --- a/adapter/wifi/oh_lite/adapter_wifi.c +++ b/adapter/wifi/oh_lite/adapter_wifi.c @@ -743,7 +743,7 @@ int32_t AdapterConnectWifi(void) ADAPTER_LOGE("ssid null"); return IOTC_ADAPTER_WIFI_ERR_GET_INFO; } - + ADAPTER_LOGE("ssid %s,pwd %s", config.ssid, config.preSharedKey); for (uint32_t i = 0; i < MAX_SCAN_TIMES; ++i) { if (AdvanceScanWifiByOhos(&config) != IOTC_OK) { ADAPTER_LOGE("advance scan wifi fail"); diff --git a/core/device/config/config_revoke_flag.c b/core/device/config/config_revoke_flag.c index 32518e9d5a3f85ff3537c94755fb0d7831fd5d92..77b294ec9dc03fbed453a91728a82207d5e0c61c 100644 --- a/core/device/config/config_revoke_flag.c +++ b/core/device/config/config_revoke_flag.c @@ -26,7 +26,7 @@ bool IsRevokeFlagExist(void) IOTC_LOGW("get revoke flag error %d", ret); return false; } - IOTC_LOGI("get revoke flag %u", flag); + //IOTC_LOGI("get revoke flag %u", flag); return flag == REVOKE_FLAG_SET; } diff --git a/core/infrastructure/service/include/iotc_svc.h b/core/infrastructure/service/include/iotc_svc.h index a7a01dd96c264b53101161f7a8ad50d1583eaf45..3fd50ac270267a6d499558a11bab61aca8e5c246 100644 --- a/core/infrastructure/service/include/iotc_svc.h +++ b/core/infrastructure/service/include/iotc_svc.h @@ -28,6 +28,7 @@ typedef enum { IOTC_SERVICE_ID_WIFI_CONNECT, IOTC_SERVICE_ID_LOCAL_CONTROL, IOTC_SERVICE_ID_LAN_SEARCH, + IOTC_SERVICE_ID_M2M_CLOUD, IOTC_SERVICE_ID_BLE = IOTC_SERVICE_ID_BASE(IOTC_SUB_MODULE_CORE_BLE), diff --git a/core/infrastructure/service/include/iotc_svc_m2m_cloud.h b/core/infrastructure/service/include/iotc_svc_m2m_cloud.h new file mode 100644 index 0000000000000000000000000000000000000000..5eac785b8d0675496a51188331ef25220eb6bb83 --- /dev/null +++ b/core/infrastructure/service/include/iotc_svc_m2m_cloud.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024-2024 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. + */ +#ifndef IOTC_SVC_M2M_CLOUD_H +#define IOTC_SVC_M2M_CLOUD_H +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + SOFTAP_SERVICE_MSG_DEVICE_E2E_CONTROL = 0, + SOFTAP_SERVICE_MSG_DEVICE_CLOUD_SETUP, + SOFTAP_SERVICE_MSG_ID_MAX, +} SoftapSvcMsgId; + +typedef enum { + IOTC_WIFI_SERVICE_SOFTAP_NETCFG = 0, + IOTC_WIFI_SERVICE_SOFTAP_E2E_CTRL, + IOTC_WIFI_SERVICE_SOFTAP_CUSTOM_SSID, + IOTC_WIFI_SERVICE_SOFTAP_TIMEOUT, +} SoftapSvcBitMap; + +typedef int32_t (*SoftapCustomBuildSsidCallback)(uint8_t *ssid, uint32_t *len); + +typedef struct { + uint32_t bitMap; + uint32_t timeoutMs; + SoftapCustomBuildSsidCallback onBuildSsid; +} SoftapSvcInitParam; + +#ifdef __cplusplus +} +#endif +#endif /* IOTC_SVC_M2M_CLOUD_H */ \ No newline at end of file diff --git a/core/wifi/application/CMakeLists.txt b/core/wifi/application/CMakeLists.txt index 4a3c6a15d11c589ca6cc4d91113d76295f5a5ac0..45a7de079b95eaaaeed7e5c1bf61a41688235fed 100644 --- a/core/wifi/application/CMakeLists.txt +++ b/core/wifi/application/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(connect) add_subdirectory(softap) add_subdirectory(local_control) add_subdirectory(lan_search) +add_subdirectory(cloud) set(IOTC_SRC_LIST ${IOTC_SRC_LIST} PARENT_SCOPE) set(IOTC_INC_LIST ${IOTC_INC_LIST} PARENT_SCOPE) diff --git a/core/wifi/application/cloud/CMakeLists.txt b/core/wifi/application/cloud/CMakeLists.txt index 342e10beac588abe7ad9a2ca955c0cc5ebb11d9e..45dd359694be3da0cd34e5ab0644ddf9a33976df 100644 --- a/core/wifi/application/cloud/CMakeLists.txt +++ b/core/wifi/application/cloud/CMakeLists.txt @@ -24,6 +24,8 @@ set(IOTC_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/m2m_cloud_token.c ${CMAKE_CURRENT_SOURCE_DIR}/m2m_cloud_utils.c ${CMAKE_CURRENT_SOURCE_DIR}/m2m_cloud.c + ${CMAKE_CURRENT_SOURCE_DIR}/m2m_cloud_svc.c + ${CMAKE_CURRENT_SOURCE_DIR}/m2m_cloud_svc_ctx.c PARENT_SCOPE ) diff --git a/core/wifi/application/cloud/include/m2m_cloud_svc.h b/core/wifi/application/cloud/include/m2m_cloud_svc.h new file mode 100644 index 0000000000000000000000000000000000000000..636a5c462cc95f873c90f56565ed114b01c84b69 --- /dev/null +++ b/core/wifi/application/cloud/include/m2m_cloud_svc.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024-2024 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. + */ +#ifndef M2M_CLOUD_SVC_H +#define M2M_CLOUD_SVC_H +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t M2mCloudServiceInit(void); + +void M2mCloudServiceDeinit(void); + +#ifdef __cplusplus +} +#endif +#endif /* M2M_CLOUD_SVC_H */ \ No newline at end of file diff --git a/core/wifi/application/cloud/link/cloud_link.c b/core/wifi/application/cloud/link/cloud_link.c index 45d79496357f4dfd82834fafdc2d2ed96dc0eaf7..e1dcbf02a7a9bb1ce24eafbcc80fc959ac9240cb 100644 --- a/core/wifi/application/cloud/link/cloud_link.c +++ b/core/wifi/application/cloud/link/cloud_link.c @@ -25,6 +25,7 @@ #include "sched_timer.h" #include "sched_event_loop.h" #include "iotc_errcode.h" +#include "trans_buffer_inner.h" #define CLOUD_RESP_TIMEOUT_MS UTILS_SEC_TO_MS(30) diff --git a/core/wifi/application/cloud/link/sess/tls/cloud_link_sess.c b/core/wifi/application/cloud/link/sess/tls/cloud_link_sess.c index ce112399c918671bfa731fd7933916fb4936fcf2..b798552c8252478a8df0bf69a6c2db86c16cfe9d 100644 --- a/core/wifi/application/cloud/link/sess/tls/cloud_link_sess.c +++ b/core/wifi/application/cloud/link/sess/tls/cloud_link_sess.c @@ -16,14 +16,13 @@ #include "trans_socket_tls.h" #include "securec.h" #include "utils_common.h" -#include "trans_sess_coap.h" #include "coap_codec_tcp_v1.h" #include "wifi_sched_fd_watch.h" -#include "wifi_product.h" #include "utils_assert.h" #include "adapter_socket.h" #include "coap_codec_utils.h" #include "iotc_errcode.h" +#include "product_adapter.h" static const char *TLS_SESS_NAME = "cloud_tls"; @@ -47,7 +46,7 @@ static int32_t CloudTlsTransLinkInit(CloudLink *ctx, CloudTcpUpdateRemainLen rem tlsParam.suites.ciphersuites = ciphersuites; tlsParam.suites.num = ARRAY_SIZE(ciphersuites); - int32_t ret = WifiGetCaCert(&tlsParam.cert.certs, &tlsParam.cert.num); + int32_t ret = ProductGetRootCaCert(&tlsParam.cert.certs, &tlsParam.cert.num); if (ret != IOTC_OK) { IOTC_LOGW("get ca error %d", ret); return ret; @@ -103,7 +102,7 @@ SessCode CloudTlsSessSendUpdateSeqProcess(SessMsg *msg, UtilsBuffer *buf, SessAd return SESS_CODE_ERR; } uint32_t seqNet = AdapterHtonl(*seq); - int32_t ret = memcpy_s(seqOption->value.data, seqOption->value.len, &seqNet, sizeof(seqNet)); + int32_t ret = memcpy_s((void *)seqOption->value.data, seqOption->value.len, &seqNet, sizeof(seqNet)); if (ret != EOK) { return IOTC_ERR_SECUREC_MEMCPY; } diff --git a/core/wifi/application/cloud/m2m_cloud.c b/core/wifi/application/cloud/m2m_cloud.c index 5c81d89d31a0dda6635ca72ec37d4c48bd183fb5..0a875952f90e67efe9f9a9cbfd0b4337d0dca6b1 100644 --- a/core/wifi/application/cloud/m2m_cloud.c +++ b/core/wifi/application/cloud/m2m_cloud.c @@ -411,6 +411,13 @@ static void WifiNetDisconnectEventCallback(uint32_t event, void *param, uint32_t UtilsFsmSwitch(GetM2mCloudFsm(), M2M_CLOUD_FSM_STATE_EXIT); } +static void M2mPeriodProcess(int32_t id, void *userData) +{ + NOT_USED(id); + NOT_USED(userData); + M2mCloudFsmProcess(); +} + int32_t M2mCloudInit(void) { (void)memset_s(GetM2mCloudCtx(), sizeof(M2mCloudCtx), 0, sizeof(M2mCloudCtx)); @@ -427,6 +434,13 @@ int32_t M2mCloudInit(void) IOTC_LOGW("token init error"); return ret; } + int timerFd = SchedTimerAdd(EVENT_SOURCE_TIMER_TYPE_REPEAT, + M2mPeriodProcess, 50, NULL); + if (timerFd < 0) { + ret = timerFd; + IOTC_LOGW("add timer err ret:%d", ret); + return ret; + } return IOTC_OK; } diff --git a/core/wifi/application/cloud/m2m_cloud_svc.c b/core/wifi/application/cloud/m2m_cloud_svc.c new file mode 100644 index 0000000000000000000000000000000000000000..d648a9fcca34a4b271a884d498d9966b75e30d0c --- /dev/null +++ b/core/wifi/application/cloud/m2m_cloud_svc.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2024-2024 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. + */ +#include "m2m_cloud_svc.h" +#include "iotc_svc.h" +#include "iotc_svc_m2m_cloud.h" +#include "m2m_cloud_svc_ctx.h" +#include "m2m_cloud.h" +#include "iotc_log.h" +#include "sched_timer.h" +#include "utils_assert.h" +#include "securec.h" +#include "adapter_wifi.h" +#include "utils_common.h" +#include "utils_bit_map.h" +#include "service_manager.h" +#include "event_bus.h" +#include "service_proxy.h" +#include "iotc_errcode.h" +#include "iotc_event.h" + +static const char *M2M_CLOUD_SERVICE_NAME = "M2M_CLOUD"; + +#define M2M_PROCESS_TIMER_PERIOD UTILS_SEC_TO_MS(50) + +static void M2mCloudServiceExit(void) +{ + M2mCloudServiceContext *ctx = GetM2mCloudServiceContext(); + if (ctx == NULL) { + return; + } + if (ctx->timerFd >= 0) { + SchedTimerRemove(ctx->timerFd); + ctx->timerFd = EVENT_SOURCE_INVALID_TIMER_FD; + } + + if (ctx->onFinish != NULL) { + ctx->onFinish(ctx->instanceId); + } + + M2mCloudServiceContextDeinit(); +} + +static int32_t StartM2mCloudService(int32_t instanceId, ServiceFinishCallback onFinish, void *param) +{ + CHECK_RETURN_LOGW(onFinish != NULL, IOTC_ERR_PARAM_INVALID, "param invalid"); + if (GetM2mCloudServiceContext() != NULL) { + M2mCloudServiceExit(); + } + int32_t ret; + do { + /* 1. 初始化上下文 */ + ret = M2mCloudServiceContextInit(); + if (ret != IOTC_OK) { + IOTC_LOGW("context init err ret:%d", ret); + break; + } + M2mCloudServiceContext *ctx = GetM2mCloudServiceContext(); + if (ctx == NULL) { + ret = IOTC_CORE_WIFI_M2M_ERR_CLOUD_INVALID_CTX; + IOTC_LOGW("context is null ret:%d", ret); + break; + } + ctx->onFinish = onFinish; + ctx->instanceId = instanceId; + + ret = M2mCloudInit(); + if (ret != IOTC_OK) { + IOTC_LOGW("m2m cloud init err ret:%d", ret); + break; + } + + IOTC_LOGN("m2m cloud service start success"); + return IOTC_OK; + } while (0); + + /* 异常处理 */ + M2mCloudServiceExit(); + return ret; +} + +static int32_t StopM2mCloudService(int32_t instanceId, void *param) +{ + IOTC_LOGN("m2m cloud service stop"); + M2mCloudServiceContext *ctx = GetM2mCloudServiceContext(); + if (ctx == NULL) { + return IOTC_CORE_WIFI_M2M_ERR_CLOUD_INVALID_CTX; + } + if (instanceId != ctx->instanceId) { + IOTC_LOGW("invalid instance id to stop %d", instanceId); + return IOTC_ERR_PARAM_INVALID; + } + + M2mCloudServiceExit(); + return IOTC_OK; +} + +int32_t M2mCloudServiceInit(void) +{ + static const ServiceHandler M2M_CLOUD_SERVICE_HANDLER = { + .onStart = StartM2mCloudService, + .onStop = StopM2mCloudService, + .onReset = NULL, + }; + + ServiceInstance instance = { + .serviceId = IOTC_SERVICE_ID_M2M_CLOUD, + .name = M2M_CLOUD_SERVICE_NAME, + .handler = &M2M_CLOUD_SERVICE_HANDLER, + .msgNum = 0, + .msgIds = NULL, + .apiHandler = NULL, + }; + + int32_t ret = ServiceManagerRegisterInstance(&instance); + if (ret != IOTC_OK) { + IOTC_LOGE("reg m2m cloud service instance error %d", ret); + return ret; + } + return IOTC_OK; +} + + + +void M2mCloudServiceDeinit(void) +{ + (void)M2mCloudServiceExit(); + ServiceManagerUnregisterInstance(IOTC_SERVICE_ID_M2M_CLOUD); +} \ No newline at end of file diff --git a/core/wifi/application/cloud/m2m_cloud_svc_ctx.c b/core/wifi/application/cloud/m2m_cloud_svc_ctx.c new file mode 100644 index 0000000000000000000000000000000000000000..1d967f851453f4c01a92317ceda2b396dcce5292 --- /dev/null +++ b/core/wifi/application/cloud/m2m_cloud_svc_ctx.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024-2024 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. + */ +#include "m2m_cloud_svc_ctx.h" +#include "utils_common.h" +#include "iotc_log.h" +#include "securec.h" +#include "sched_timer.h" +#include "iotc_errcode.h" + +static M2mCloudServiceContext *g_m2mCloudSvcCtx = NULL; + +M2mCloudServiceContext *GetM2mCloudServiceContext() +{ + return g_m2mCloudSvcCtx; +} + +int32_t M2mCloudServiceContextInit(void) +{ + g_m2mCloudSvcCtx = (M2mCloudServiceContext *)AdapterMalloc(sizeof(M2mCloudServiceContext)); + if (g_m2mCloudSvcCtx == NULL) { + IOTC_LOGW("malloc error"); + return IOTC_ADAPTER_MEM_ERR_MALLOC; + } + (void)memset_s(g_m2mCloudSvcCtx, sizeof(M2mCloudServiceContext), 0, sizeof(M2mCloudServiceContext)); + g_m2mCloudSvcCtx->timerFd = EVENT_SOURCE_INVALID_TIMER_FD; + return IOTC_OK; +} + +void M2mCloudServiceContextDeinit(void) +{ + UTILS_FREE_2_NULL(g_m2mCloudSvcCtx); +} \ No newline at end of file diff --git a/core/wifi/application/cloud/m2m_cloud_svc_ctx.h b/core/wifi/application/cloud/m2m_cloud_svc_ctx.h new file mode 100644 index 0000000000000000000000000000000000000000..b7d306188aca19ca6fbb7610091b1774c71be599 --- /dev/null +++ b/core/wifi/application/cloud/m2m_cloud_svc_ctx.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024-2024 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. + */ +#ifndef M2M_CLOUD_SVC_CTX_H +#define M2M_CLOUD_SVC_CTX_H + +#include +#include "service_manager.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + M2M_CLOUD_CTX_BIT_MAP_SOFTAP_STARTED = 0, +} SoftapCtxBitMap; + +typedef struct { + uint32_t bitMap; + int32_t instanceId; + int32_t timerFd; + ServiceFinishCallback onFinish; +} M2mCloudServiceContext; + +M2mCloudServiceContext *GetM2mCloudServiceContext(); + +int32_t M2mCloudServiceContextInit(void); + +void M2mCloudServiceContextDeinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* M2M_CLOUD_SVC_CTX_H */ \ No newline at end of file diff --git a/core/wifi/application/cloud/m2m_cloud_sync.c b/core/wifi/application/cloud/m2m_cloud_sync.c index 10dd8d29fea5d810400692bdb2bdc6a0c4d584b8..bcfa3d2457e29d0df2664054ab261c230f0e7440 100644 --- a/core/wifi/application/cloud/m2m_cloud_sync.c +++ b/core/wifi/application/cloud/m2m_cloud_sync.c @@ -26,30 +26,7 @@ #include "utils_bit_map.h" #include "m2m_cloud_utils.h" #include "iotc_errcode.h" - -static int32_t BuildDevInfoSyncSvcInfo(AdapterJson *rootObj) -{ - uint32_t num = 0; - const IotcServiceInfo *svcInfo = ModelGetSvcInfo(&num); - if (svcInfo == NULL || num == 0) { - IOTC_LOGW("get svc invalid %u", num); - return IOTC_CORE_PROF_MDL_ERR_SVC_NUM_INVALID; - } - AdapterJson *svcInfoArr = MdlBuildSvcJsonArray(svcInfo, num); - if (svcInfoArr == NULL) { - IOTC_LOGW("create json error"); - return IOTC_ADAPTER_JSON_ERR_CREATE; - } - - int32_t ret = AdapterJsonAddItem2Obj(rootObj, STR_JSON_SERVICES, svcInfoArr); - if (ret != IOTC_OK) { - IOTC_LOGE("add svc info to root err %d", ret); - AdapterJsonDelete(svcInfoArr); - return ret; - } - - return IOTC_OK; -} +#include "product_adapter.h" int32_t M2mCloudDevInfoSyncRespParse(const CoapPacket *resp, int32_t *errcode) { @@ -68,7 +45,7 @@ int32_t M2mCloudDevInfoSyncRespParse(const CoapPacket *resp, int32_t *errcode) } if (*errcode == CLOUD_ERRCODE_OK) { - ret = ProductReportAll(); + ret = ProductProfReportAll(); if (ret != IOTC_OK) { IOTC_LOGW("report all error %d", ret); } @@ -79,7 +56,7 @@ int32_t M2mCloudDevInfoSyncRespParse(const CoapPacket *resp, int32_t *errcode) AdapterJson *M2mCloudBuildDevInfoSyncRequest(void) { - AdapterJson *rootObj = AdapterCreateJson(); + AdapterJson *rootObj = AdapterJsonCreateArray(); if (rootObj == NULL) { IOTC_LOGW("create json error"); return NULL; @@ -87,16 +64,10 @@ AdapterJson *M2mCloudBuildDevInfoSyncRequest(void) int32_t ret; do { - ret = M2mCloudAddDevInfoToJson(rootObj); - if (ret != IOTC_OK) { - break; - } - - ret = BuildDevInfoSyncSvcInfo(rootObj); + ret = M2mCloudSyncDevInfoToJson(rootObj); if (ret != IOTC_OK) { break; } - return rootObj; } while (0); @@ -115,7 +86,7 @@ int32_t M2mCloudParseDevInfoSyncResponse(AdapterJson *json, int32_t *errcode) } if (*errcode == CLOUD_ERRCODE_OK) { - ret = ProductReportAll(); + ret = ProductProfReportAll(); if (ret != IOTC_OK) { IOTC_LOGW("report all error %d", ret); } diff --git a/core/wifi/application/cloud/m2m_cloud_utils.c b/core/wifi/application/cloud/m2m_cloud_utils.c index 3097c30d2893e6292e8269a7c2c9a0cd785c8011..5d3627cbda3ddbc60624bdfcc21cc4906fb8ca02 100644 --- a/core/wifi/application/cloud/m2m_cloud_utils.c +++ b/core/wifi/application/cloud/m2m_cloud_utils.c @@ -18,12 +18,15 @@ #include "comm_def.h" #include "iotc_log.h" #include "adapter_network.h" -#include "wifi_product.h" #include "utils_json.h" #include "dev_info.h" #include "svc_info.h" #include "dev_info_mdl.h" #include "utils_common.h" +#include "wifi_net_info.h" +#include "config_login_info.h" +#include "iotc_svc_dev.h" +#include "svc_info_mdl.h" int32_t M2mCloudAddDevInfoToJson(AdapterJson *rootObj) { @@ -60,5 +63,66 @@ int32_t M2mCloudAddDevInfoToJson(AdapterJson *rootObj) return ret; } + return IOTC_OK; +} + +static int32_t BuildDevInfoSyncSvcInfo(AdapterJson *rootObj) +{ + uint32_t num = 0; + const IotcServiceInfo *svcInfo = ModelGetSvcInfo(&num); + if (svcInfo == NULL || num == 0) { + IOTC_LOGW("get svc invalid %u", num); + return IOTC_CORE_PROF_MDL_ERR_SVC_NUM_INVALID; + } + AdapterJson *svcInfoArr = MdlBuildSvcJsonArray(svcInfo, num); + if (svcInfoArr == NULL) { + IOTC_LOGW("create json error"); + return IOTC_ADAPTER_JSON_ERR_CREATE; + } + + int32_t ret = AdapterJsonAddItem2Obj(rootObj, STR_JSON_SERVICES, svcInfoArr); + if (ret != IOTC_OK) { + IOTC_LOGE("add svc info to root err %d", ret); + AdapterJsonDelete(svcInfoArr); + return ret; + } + + return IOTC_OK; +} + +int32_t M2mCloudSyncDevInfoToJson(AdapterJson *rootObj) +{ + DevLoginInfo info = {0}; + int32_t ret = ConfigGetLoginInfo(&info); + if (ret != IOTC_OK) { + IOTC_LOGE("get login info error %d", ret); + return ret; + } + + AdapterJson *json = AdapterCreateJson(); + if (json == NULL) { + IOTC_LOGE("create json err"); + return IOTC_ERROR; + } + ret = AdapterJsonAddStr2Obj(json, STR_JSON_DEVID, info.devId); + if (ret != IOTC_OK) { + IOTC_LOGE("add devid to root err %d", ret); + return ret; + } + ret = AdapterJsonAddItem2Array(rootObj, json); + if (ret != IOTC_OK) { + IOTC_LOGE("add dev info to root err %d", ret); + return ret; + } + ret = M2mCloudAddDevInfoToJson(json); + if (ret != IOTC_OK) { + IOTC_LOGE("add dev info to root err %d", ret); + return ret; + } + ret = BuildDevInfoSyncSvcInfo(json); + if (ret != IOTC_OK) { + IOTC_LOGE("add dev info to root err %d", ret); + return ret; + } return IOTC_OK; } \ No newline at end of file diff --git a/core/wifi/application/cloud/m2m_cloud_utils.h b/core/wifi/application/cloud/m2m_cloud_utils.h index 75273ddeb23b218b13a69b925255d6472f9510da..9983219eda12e2d81951cf5cf4b4c50746bdc06a 100644 --- a/core/wifi/application/cloud/m2m_cloud_utils.h +++ b/core/wifi/application/cloud/m2m_cloud_utils.h @@ -22,6 +22,7 @@ extern "C" { #endif int32_t M2mCloudAddDevInfoToJson(AdapterJson *rootObj); +int32_t M2mCloudSyncDevInfoToJson(AdapterJson *rootObj); #ifdef __cplusplus } diff --git a/core/wifi/core_wifi.gni b/core/wifi/core_wifi.gni index 69224d8c384f82c192acb7e40d15380e341f0e37..8a21e2cd315faacd8483a8f9a82033269bb76c99 100644 --- a/core/wifi/core_wifi.gni +++ b/core/wifi/core_wifi.gni @@ -68,6 +68,18 @@ iotc_core_wifi_src = [ "$wifi_core_path/application/local_control/local_ctl_report.c", "$wifi_core_path/application/local_control/local_ctl_sess.c", "$wifi_core_path/application/local_control/local_ctl_svc.c", + "$wifi_core_path/application/cloud/cloud_backoff.c", + "$wifi_core_path/application/cloud/m2m_cloud_login.c", + "$wifi_core_path/application/cloud/m2m_cloud_reg.c", + "$wifi_core_path/application/cloud/m2m_cloud_send.c", + "$wifi_core_path/application/cloud/m2m_cloud_sync.c", + "$wifi_core_path/application/cloud/m2m_cloud_token.c", + "$wifi_core_path/application/cloud/m2m_cloud_utils.c", + "$wifi_core_path/application/cloud/m2m_cloud.c", + "$wifi_core_path/application/cloud/m2m_cloud_svc.c", + "$wifi_core_path/application/cloud/m2m_cloud_svc_ctx.c", + "$wifi_core_path/application/cloud/link/cloud_link.c", + "$wifi_core_path/application/cloud/link/sess/tls/cloud_link_sess.c", "$wifi_core_path/infrastructure/schedule/wifi_sched_fd_watch.c", "$wifi_core_path/infrastructure/transport/coap/codec/coap_codec_comm.c", "$wifi_core_path/infrastructure/transport/coap/codec/coap_codec_tcp_v1.c", diff --git a/core/wifi/infrastructure/transport/socket/trans_socket_tls.c b/core/wifi/infrastructure/transport/socket/trans_socket_tls.c index ed21951898817387e9829990e4b9609cafa72346..3a71f5e3326e1a6a297856e12e7243ea3188c518 100644 --- a/core/wifi/infrastructure/transport/socket/trans_socket_tls.c +++ b/core/wifi/infrastructure/transport/socket/trans_socket_tls.c @@ -69,7 +69,7 @@ static int32_t TlsInitParamCopy(const SocketTlsInitParam *src, SocketTlsInitPara dst->suites.num = src->suites.num; uint32_t size = src->suites.num * sizeof(int32_t); - dst->suites.ciphersuites = (int32_t *)UtilsMallocCopy((uint8_t *)dst->suites.ciphersuites, + dst->suites.ciphersuites = (int32_t *)UtilsMallocCopy((uint8_t *)src->suites.ciphersuites, src->suites.num * sizeof(int32_t)); if (dst->suites.ciphersuites == NULL) { IOTC_LOGW("clone error %u", size); diff --git a/core/wifi/interfaces/core_wifi_init.c b/core/wifi/interfaces/core_wifi_init.c index 82eccb1cdcc8a3578c3b046e13a19093f26c33b6..8088114ca983e6443e0a24dacd3f8db64678c5c8 100644 --- a/core/wifi/interfaces/core_wifi_init.c +++ b/core/wifi/interfaces/core_wifi_init.c @@ -23,6 +23,7 @@ #include "iotc_errcode.h" #include "lan_search_svc.h" #include "local_ctl_svc.h" +#include "m2m_cloud_svc.h" static const FwkInitUnit CORE_WIFI[] = { /* 链路收发缓冲区组件 */ @@ -34,6 +35,7 @@ static const FwkInitUnit CORE_WIFI[] = { {FWK_INIT_LVL_BIZ, "wifi_connect", WifiServiceConnectInit, WifiServiceConnectDeinit}, {FWK_INIT_LVL_BIZ, "lan_search", LanSearchServiceInit, LanSearchServiceDeinit}, {FWK_INIT_LVL_BIZ, "local_control", LocalControlServiceInit, LocalControlServiceDeinit}, + {FWK_INIT_LVL_BIZ, "m2m_cloud", M2mCloudServiceInit, M2mCloudServiceDeinit}, }; int32_t CoreWifiRegisterInitItem(void) diff --git a/demo/oh_connect/iotc_oh_demo_combo.c b/demo/oh_connect/iotc_oh_demo_combo.c index 69c1f9171199e25f7ee66aa809fb6322667d6432..3c851ad1da6de511e1ebf5f9e6ccb5dab1beaefb 100644 --- a/demo/oh_connect/iotc_oh_demo_combo.c +++ b/demo/oh_connect/iotc_oh_demo_combo.c @@ -24,6 +24,8 @@ #include "cJSON.h" #include "iotc_conf.h" +#define IOTC_CONF_AILIFE_SUPPORT 1 + #define DEMO_LOG(...) do { \ printf("DEMO[%s:%u]", __func__, __LINE__); \ printf(__VA_ARGS__); \ @@ -67,6 +69,30 @@ const uint8_t AC_KEY[IOTC_AC_KEY_LEN] = { static bool g_switch = false; +typedef void AdapterJson; +AdapterJson *AdapterCreateJson(void); +void AdapterJsonDelete(AdapterJson *json); +AdapterJson *AdapterJsonParse(const char *str); +int32_t DevSvcProxyRecvBindInfo(const AdapterJson *str); +int32_t ConnSvcProxySetNetCfgInfo(const AdapterJson *json); + +static int32_t RecvNetcfgInfo(const char *netInfo, uint32_t len) +{ + if (netInfo == NULL) { + return -1; + } + DEMO_LOG("recv netinfo: %s", netInfo); + AdapterJson *root = AdapterJsonParse(netInfo); + if (root == NULL) { + DEMO_LOG("err"); + return -1; + } + DevSvcProxyRecvBindInfo(root); + ConnSvcProxySetNetCfgInfo(root); + AdapterJsonDelete(root); + return 0; +} + static int32_t SwitchPutCharState(const IotcServiceInfo *svc, const char *data, uint32_t len) { if (data == NULL || len == 0) { @@ -397,7 +423,9 @@ int32_t IotcOhDemoEntry(void) SET_OH_SDK_OPTION(ret, IOTC_OH_OPTION_DEVICE_SVC_INFO, SVC_INFO, sizeof(SVC_INFO) / sizeof(SVC_INFO[0])); SET_OH_SDK_OPTION(ret, IOTC_OH_OPTION_WIFI_NETCFG_MODE, IOTC_NET_CONFIG_MODE_BLE_SUP); SET_OH_SDK_OPTION(ret, IOTC_OH_OPTION_WIFI_NETCFG_TIMEOUT, (10 * 60 * 1000)); + SET_OH_SDK_OPTION(ret, IOTC_OH_OPTION_BLE_START_UP_ADV_TIMEOUT, (10 * 60 * 1000)); SET_OH_SDK_OPTION(ret, IOTC_OH_OPTION_WIFI_GET_CERT_CALLBACK, GetRootCA); + SET_OH_SDK_OPTION(ret, IOTC_OH_OPTION_BLE_RECV_NETCFG_CALLBACK, RecvNetcfgInfo); ret = IotcOhMain(); if (ret != 0) { diff --git a/interfaces/kits/common/iotc_conf.h b/interfaces/kits/common/iotc_conf.h index 45b259c6b4f01ff7bf7b365450896c8d2b3dbf0f..15571881a67d2e8cc403ed9b080211b3cba51edc 100644 --- a/interfaces/kits/common/iotc_conf.h +++ b/interfaces/kits/common/iotc_conf.h @@ -110,6 +110,7 @@ #define IOTC_CONF_MEM_DEBUG_NO_FREE 0 #endif +#define IOTC_CONF_AILIFE_SUPPORT 1 #ifndef IOTC_CONF_AILIFE_SUPPORT #define IOTC_CONF_AILIFE_SUPPORT 0 #endif diff --git a/iotc.gni b/iotc.gni index 479e01975baf59fe4db7c1f1b5acbe4945afd68d..fe72413c626496f3232115db969b2f11872a97af 100644 --- a/iotc.gni +++ b/iotc.gni @@ -22,7 +22,7 @@ iotc_demo_path = "${iotc_root_path}/demo" declare_args() { iotc_ble_support = true iotc_wifi_support = true - iotc_ailife_support = false + iotc_ailife_support = true iotc_demo_support = false iotc_demo_type = "combo" iotc_mbedtls_v2_support = false diff --git a/sdk/oh_connect/api/iotc_oh_connect.c b/sdk/oh_connect/api/iotc_oh_connect.c index 5fc3a0a89e5ee18470360108c89fe30952a1d64d..9ffa1ec3edf8f7b529382b912a966bff58f2f437 100644 --- a/sdk/oh_connect/api/iotc_oh_connect.c +++ b/sdk/oh_connect/api/iotc_oh_connect.c @@ -28,7 +28,7 @@ #include "product_adapter.h" #define IOTC_OH_RESTORE_TIMEOUT UTILS_SEC_TO_MS(10) -#define IOTC_OH_DEFAULT_TASK_SIZE 0X8000 +#define IOTC_OH_DEFAULT_TASK_SIZE 0X2000 static const FwkInitUnit OH_COMM[] = { {FWK_INIT_LVL_BIZ, "config", IotcOhStoreDataInit, IotcOhStoreDataDeinit}, }; diff --git a/sdk/oh_connect/api/iotc_oh_wifi.c b/sdk/oh_connect/api/iotc_oh_wifi.c index b5155311403e19c86afc60fa312ffe57dd9bca67..1f0e8f8beb965b44014be6996ceaf090d2addbf5 100644 --- a/sdk/oh_connect/api/iotc_oh_wifi.c +++ b/sdk/oh_connect/api/iotc_oh_wifi.c @@ -97,6 +97,12 @@ static void EventBusStartWifiSvcCallback(uint32_t event, void *param, uint32_t l return; } + ret = ServiceProxyStartService(IOTC_SERVICE_ID_M2M_CLOUD, NULL); + if (ret != IOTC_OK) { + IOTC_LOGE("start m2m cloud error %d", ret); + return; + } + return; }