├── certs └── README.md ├── external_libs ├── wslay │ ├── Makefile │ ├── lib │ │ ├── includes │ │ │ ├── Makefile.am │ │ │ └── wslay │ │ │ │ ├── wslayver.h.in │ │ │ │ └── wslayver.h │ │ ├── Makefile │ │ ├── wslay_net.c │ │ ├── wslay_net.h │ │ ├── wslay_stack.h │ │ ├── wslay_queue.h │ │ ├── CMakeLists.txt │ │ ├── wslay_stack.c │ │ └── wslay_frame.h │ └── CMakeLists.txt └── mbedtls │ ├── configs │ ├── README.txt │ ├── config-picocoin.h │ ├── config-mini-tls1_1.h │ ├── config-no-entropy.h │ ├── config-thread.h │ └── config-ccm-psk-tls1_2.h │ ├── include │ └── mbedtls │ │ ├── net.h │ │ ├── havege.h │ │ ├── platform_time.h │ │ ├── arc4.h │ │ └── base64.h │ ├── library │ └── version.c │ └── Makefile ├── tools ├── build_scripts │ ├── rules-tests.mk │ ├── update_gtest.sh │ ├── update_mbedtls.sh │ ├── stats_static_lib.sh │ └── rules.mk ├── cmake_scripts │ ├── convert.sh │ └── config.h.in └── update_from_old_SDK.sh ├── .clang-format ├── .gitignore ├── CMakeSettings.json ├── device_info.json ├── include ├── config.h ├── utils_getopt.h ├── exports │ ├── qcloud_iot_export_dynreg.h │ ├── qcloud_iot_export_broadcast.h │ ├── qcloud_iot_export_system.h │ └── qcloud_iot_export_rrpc.h ├── platform.h ├── qcloud_iot_export_variables.h └── qcloud_iot_export.h ├── docs ├── C-SDK_MTMC多线程多设备支持.md ├── IoT_Hub │ ├── log_upload_设备日志上报.md │ ├── IoT_Hub通信平台快速入门.md │ └── coap_sample_CoAP通讯.md ├── MCU+腾讯云定制AT模组.md ├── en │ ├── MCU+Tencent Cloud IoT AT instruction_EN-US.md │ ├── C-SDK Multi-Thread and Multi-Device Support_EN-US.md │ ├── IoT_Hub │ │ ├── log_upload_Device Log Reporting_EN-US.md │ │ ├── IoT_Hub C-SDK Getting Started_EN-US.md │ │ └── coap_sample_CoAP Communication_EN-US.md │ └── MCU+ universal TCP AT module Porting((FreeRTOS))_EN-US.md ├── MCU+通用TCP_AT模组移植(FreeRTOS).md ├── MCU+通用TCP_AT模组移植(nonOS).md └── FreeRTOS+lwIP平台移植说明.md ├── sdk_src ├── internal_inc │ ├── coap_client_net.h │ ├── qcloud_iot_device.h │ ├── system_mqtt_ssh_proxy.h │ ├── utils_hmac.h │ ├── mqtt_client_net.h │ ├── ota_fetch.h │ ├── utils_base64.h │ ├── resource_lib.h │ ├── resource_upload.h │ ├── utils_url_upload.h │ ├── qcloud_iot_ca.h │ ├── utils_websocket_client.h │ ├── at_utils.h │ ├── utils_ringbuff.h │ ├── ota_client.h │ ├── shadow_client_common.h │ ├── resource_client.h │ ├── qcloud_iot_http.h │ ├── utils_list.h │ ├── at_uart_hal.h │ ├── utils_sha1.h │ ├── utils_md5.h │ ├── ota_lib.h │ ├── utils_httpc.h │ ├── log_upload.h │ ├── utils_timer.h │ └── qcloud_iot_common.h ├── protocol │ ├── coap │ │ └── coap_client_net.c │ └── mqtt │ │ └── mqtt_client_net.c ├── utils │ ├── qcloud_iot_device.c │ ├── utils_ringbuff.c │ ├── utils_timer.c │ └── utils_getopt.c └── services │ └── resource │ ├── resource_upload.c │ └── resource_lib.c ├── platform ├── at_device │ └── esp8266 │ │ └── at_device_esp8266.h ├── CMakeLists.txt └── os │ ├── windows │ ├── HAL_AT_UART_win.c │ └── HAL_Log_win.c │ ├── nonos │ ├── HAL_OS_nonos.c │ ├── HAL_AT_UART_nonos.c │ └── HAL_Timer_nonos.c │ ├── freertos │ └── HAL_AT_UART_freertos.c │ ├── linux │ ├── HAL_Log_linux.c │ └── HAL_Timer_linux.c │ └── rtthread │ └── HAL_Timer_rtthread.c ├── LICENSE └── cmake_build.sh /certs/README.md: -------------------------------------------------------------------------------- 1 | 该目录用于存放两个文件: 2 | 1. 客户端证书文件; 3 | 2. 客户端私钥文件, 该文件需与客户端证书文件一一对应。 -------------------------------------------------------------------------------- /external_libs/wslay/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .SILENT: 3 | 4 | .PHONY: all lib clean 5 | 6 | all: lib 7 | echo "123 $(CFLAGS)" 8 | $(MAKE) -s -C lib 9 | 10 | lib: 11 | $(MAKE) -s -C lib 12 | 13 | clean: 14 | $(MAKE) -C lib clean 15 | -------------------------------------------------------------------------------- /tools/build_scripts/rules-tests.mk: -------------------------------------------------------------------------------- 1 | .PHONY: run_demo_test demo_test_clean run_unit_test run_multi_thread_test \ 2 | coap_run_demo_test coap_demo_test_clean 3 | 4 | tests: run_demo_test run_unit_test run_multi_thread_test coap_run_demo_test 5 | -------------------------------------------------------------------------------- /tools/build_scripts/update_gtest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GOOGLE_TEST="external_libs/googletest" 4 | 5 | if [ ! -d ${GOOGLE_TEST} ]; then 6 | git clone -q packages/gtest_module.git ${GOOGLE_TEST} 7 | else 8 | cd ${GOOGLE_TEST} 9 | git pull -q 10 | cd - 11 | fi -------------------------------------------------------------------------------- /tools/build_scripts/update_mbedtls.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MBEDTLS_DIR="external_libs/mbedtls" 4 | 5 | if [ ! -d ${MBEDTLS_DIR} ]; then 6 | git clone -q packages/mbedtls_module.git ${MBEDTLS_DIR} 7 | else 8 | cd ${MBEDTLS_DIR} 9 | git pull -q 10 | cd - 11 | fi 12 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | BreakBeforeBraces: Linux 3 | AlignConsecutiveDeclarations: true 4 | AlignConsecutiveMacros: true 5 | AlignConsecutiveAssignments: true 6 | AllowShortFunctionsOnASingleLine: Inline 7 | AllowShortIfStatementsOnASingleLine: false 8 | SortIncludes: false 9 | IndentWidth: 4 10 | ColumnLimit: 120 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | ./build/ 3 | /build 4 | *.o 5 | *.a 6 | /*.cproject 7 | /*.autotools 8 | /.project 9 | /output 10 | .DS_Store 11 | *.DS_Store 12 | *.crt 13 | *.key 14 | sdk-tests/certs/unittest_private.key 15 | sdk-tests/certs/unittest_private.key 16 | /.vscode/settings.json 17 | /.vs 18 | upload-fail-save.log 19 | local_fw_info.json 20 | ota.bin 21 | -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "x86-Debug", 5 | "generator": "Ninja", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ 8 | "msvc_x86" 9 | ], 10 | "buildRoot": "${projectDir}\\build\\${name}", 11 | "installRoot": "${projectDir}\\build\\install\\${name}", 12 | "cmakeCommandArgs": "", 13 | "buildCommandArgs": "-v", 14 | "ctestCommandArgs": "" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /tools/cmake_scripts/convert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $1 == "linux" ]; then 4 | find $2 -type f -name "*.h" -print -o -name "*.c" -print | xargs -i sed -i '1 s/^\xef\xbb\xbf//' {} 5 | echo "Convert source files to Unix format!!!" 6 | elif [ $1 == "windows" ]; then 7 | find $2 -type f -name "*.h" -print -o -name "*.c" -print | xargs -i sed -i '1 s/^/\xef\xbb\xbf&/' {} 8 | echo "Convert source files to Windows format!!!" 9 | else 10 | echo "Invaild argument!" 11 | echo "Please choose windows or linux !!!" 12 | fi 13 | -------------------------------------------------------------------------------- /device_info.json: -------------------------------------------------------------------------------- 1 | { 2 | "auth_mode":"KEY", 3 | "region":"china", 4 | "productId":"PRODUCT_ID", 5 | "productSecret":"YOUR_PRODUCT_SECRET", 6 | "deviceName":"YOUR_DEV_NAME", 7 | 8 | "key_deviceinfo":{ 9 | "deviceSecret":"YOUR_IOT_PSK" 10 | }, 11 | 12 | "cert_deviceinfo":{ 13 | "devCertFile":"YOUR_DEVICE_CERT_FILE_NAME", 14 | "devPrivateKeyFile":"YOUR_DEVICE_PRIVATE_KEY_FILE_NAME" 15 | }, 16 | 17 | "subDev":{ 18 | "sub_productId":"YOUR_SUBDEV_PRODUCT_ID", 19 | "sub_devName":"YOUR_SUBDEV_DEVICE_NAME" 20 | } 21 | } -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /* #undef AUTH_MODE_CERT */ 2 | #define AUTH_MODE_KEY 3 | #define AUTH_WITH_NOTLS 4 | #define GATEWAY_ENABLED 5 | /* #undef COAP_COMM_ENABLED */ 6 | #define OTA_MQTT_CHANNEL 7 | #define SYSTEM_COMM 8 | #define DEV_DYN_REG_ENABLED 9 | /* #undef LOG_UPLOAD */ 10 | /* #undef IOT_DEBUG */ 11 | /* #undef DEBUG_DEV_INFO_USED */ 12 | /* #undef AT_TCP_ENABLED */ 13 | /* #undef AT_UART_RECV_IRQ */ 14 | /* #undef AT_OS_USED */ 15 | /* #undef AT_DEBUG */ 16 | #define OTA_USE_HTTPS 17 | #define MULTITHREAD_ENABLED 18 | #define BROADCAST_ENABLED 19 | #define RRPC_ENABLED 20 | #define REMOTE_CONFIG_MQTT 21 | -------------------------------------------------------------------------------- /tools/cmake_scripts/config.h.in: -------------------------------------------------------------------------------- 1 | #cmakedefine AUTH_MODE_CERT 2 | #cmakedefine AUTH_MODE_KEY 3 | #cmakedefine AUTH_WITH_NOTLS 4 | #cmakedefine GATEWAY_ENABLED 5 | #cmakedefine COAP_COMM_ENABLED 6 | #cmakedefine OTA_MQTT_CHANNEL 7 | #cmakedefine SYSTEM_COMM 8 | #cmakedefine DEV_DYN_REG_ENABLED 9 | #cmakedefine LOG_UPLOAD 10 | #cmakedefine IOT_DEBUG 11 | #cmakedefine DEBUG_DEV_INFO_USED 12 | #cmakedefine AT_TCP_ENABLED 13 | #cmakedefine AT_UART_RECV_IRQ 14 | #cmakedefine AT_OS_USED 15 | #cmakedefine AT_DEBUG 16 | #cmakedefine OTA_USE_HTTPS 17 | #cmakedefine MULTITHREAD_ENABLED 18 | #cmakedefine BROADCAST_ENABLED 19 | #cmakedefine RRPC_ENABLED 20 | #cmakedefine REMOTE_CONFIG_MQTT 21 | #cmakedefine RESOURCE_USE_HTTPS 22 | #cmakedefine REMOTE_LOGIN_WEBSOCKET_SSH 23 | #cmakedefine WEBSOCKET_CLIENT 24 | #cmakedefine WEBSOCKET_MQTT 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/C-SDK_MTMC多线程多设备支持.md: -------------------------------------------------------------------------------- 1 | # C-SDK 多线程及多设备支持 2 | 3 | 多线程及多设备支持实例需要首先使能编译配置开关FEATURE_MULTITHREAD_ENABLED 4 | 5 | ## Multi-Thread 多线程环境使用说明 6 | 7 | 设备端 C-SDK 支持在多线程多任务环境下使用,但是对接口的使用有一定规范。 8 | 比如对于MQTT接口在多线程环境下的使用有如下注意事项: 9 | ``` 10 | 1. 不允许多线程调用IOT_MQTT_Yield,IOT_MQTT_Construct以及IOT_MQTT_Destroy 11 | 2. 可以多线程调用IOT_MQTT_Publish,IOT_MQTT_Subscribe及IOT_MQTT_Unsubscribe 12 | 3. IOT_MQTT_Yield 作为从socket读取并处理MQTT报文的函数,应保证一定的执行时间,避免被长时间挂起或抢占 13 | ``` 14 | 在多线程环境下,建议可以使用 IOT_MQTT_StartLoop 和 IOT_MQTT_StopLoop 来启动和停止后台 IOT_MQTT_Yield 线程,则在需要读取报文的时候不再需要主动调用IOT_MQTT_Yield函数,由后台线程来读取并处理MQTT报文。 15 | 使用示例可以参考 samples/mqtt/multi_thread_mqtt_sample 16 | 17 | 其他模块接口的使用可以参考MQTT接口的使用 18 | 19 | ## Multi-Client 多设备接入使用 20 | 21 | 在SDK版本3.2.0之后,支持同时使用多个设备接入。SDK采用面向对象方式对状态变量和参数进行封装,使得比如一个MQTT/Shadow Client实例可以对应一个设备,通过提供多个设备三元组,创建多个Client实例,则可以同时进行多个设备的接入和通讯。 22 | 具体的示例代码可以参考 samples/multi_client 下面的sample,通过创建多个线程,每个线程里面创建各自的 MQTT/Shadow Client,则相当于多个设备在同时访问后台服务。 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/IoT_Hub/log_upload_设备日志上报.md: -------------------------------------------------------------------------------- 1 | # 设备日志上报功能 2 | ## 功能简介 3 | 设备端日志上报功能,可将设备端的Log通过HTTP上报到云端,并可在控制台展示,方便用户远程调试、诊断及监控设备运行状况。目前该功能仅支持MQTT模式。 4 | 只要将SDK的编译宏FEATURE_LOG_UPLOAD_ENABLED置为y(默认为y),并在控制台设置上报级别,则在代码中调用Log_e/w/i/d接口的日志除了会在终端打印出来,还会上报云端并在控制台展示,如下图。 5 | ![](https://main.qcloudimg.com/raw/cae7f9e7cf1e354cfc1e3578eb6746bc.png) 6 | 7 | ## 日志级别 8 | 上报级别设置可参见下图,Level级别越大则上报的日志越多,比如Level3(信息)会将ERROR/WARN/INFO级别的日志都上报而DEBUG级别则不上报。控制台默认为关闭状态,则表示设备端仅在MQTT连接失败的时候才会上报ERROR级别日志。 9 | ![](https://main.qcloudimg.com/raw/826b648993a267b1cc2f082148d8d073.png) 10 | 11 | ## 功能使用 12 | 代码具体用例可以参考mqtt_sample以及qcloud_iot_export_log.h注释说明,用户除了打开编译宏开关,还需要调用IOT_Log_Init_Uploader函数进行初始化。SDK在IOT_MQTT_Yield函数中会定时进行上报,此外,用户可根据自身需要,在程序出错退出的时候调用IOT_Log_Upload(true)强制上报。同时SDK提供在HTTP通讯出错无法上报日志时的缓存和恢复正常后重新上报机制,但需要用户根据设备具体情况提供相关回调函数,如不提供回调或回调函数提供不全则该缓存机制不生效,HTTP通讯失败时日志会被丢掉。 13 | 14 | 打开日志上报功能,请确保编译配置文件CMakeLists.txt中使能下面选项 15 | ``` 16 | set(FEATURE_LOG_UPLOAD_ENABLED ON) 17 | ``` 18 | -------------------------------------------------------------------------------- /include/utils_getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef __UTILS_GETOPT_H__ 17 | #define __UTILS_GETOPT_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | extern char* utils_optarg; /* pointer to argument of current option */ 24 | int utils_getopt(int nargc, char* const* nargv, const char* options); 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/coap_client_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_COAP_CLIENT_NET_H_ 17 | #define IOT_COAP_CLIENT_NET_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #include "network_interface.h" 26 | 27 | int qcloud_iot_coap_network_init(Network *pNetwork); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif /* IOT_COAP_CLIENT_NET_H_ */ 33 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/qcloud_iot_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_DEVICE_H_ 17 | #define IOT_DEVICE_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "qcloud_iot_export.h" 24 | #include "qcloud_iot_import.h" 25 | 26 | int iot_device_info_set(DeviceInfo *device_info, const char *product_id, const char *device_name); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* IOT_DEVICE_H_ */ 33 | -------------------------------------------------------------------------------- /docs/IoT_Hub/IoT_Hub通信平台快速入门.md: -------------------------------------------------------------------------------- 1 | # 腾讯云物联网通信 C-SDK 2 | 腾讯云物联网通信IoT Hub C-SDK 依靠安全且性能强大的数据通道,为物联网领域开发人员提供设备终端和云端的双向通信能力。 3 | 以下为SDK各项功能对应的文档。 4 | 5 | ## 快速入门 6 | 请参考**mqtt_sample_快速入门.md**文档,介绍如何在腾讯云物联网通信IoT Hub控制台创建设备, 并结合本 SDK 的**mqtt_sample**快速体验设备端通过 MQTT 协议连接到腾讯云IoT Hub, 发送和接收消息。 7 | 8 | ## 设备影子 9 | 请参考**shadow_sample_设备影子.md**文档,介绍设备影子功能,并结合 SDK 的**shadow_sample**展示影子的数据流和功能 10 | 11 | ## 固件升级 12 | 请参考**ota_sample_固件升级.md**文档,介绍固件升级功能,并结合 SDK 的**ota_mqtt_sample**展示固件升级的流程和功能 13 | 14 | ## 网关功能 15 | 请参考**gateway_sample_网关功能.md**文档,介绍如何在腾讯IoT Hub控制台申请网关设备并绑定子设备, 并结合本 SDK 的**gateway_sample**快速体验网关设备通过 MQTT 协议连接到腾讯云IoT Hub, 代理子设备上下线,发送和接收消息。 16 | 17 | ## 设备互通 18 | 请参考**door_aircond_sample_设备互通.md**文档,介绍一个智能家居设备互通的场景, 结合本 SDK 的**aircond_shadow_sample**和**door_mqtt_sample**快速体验基于IoT Hub的消息转发和规则引擎实现设备之间的联动。 19 | 20 | ## 动态注册 21 | 请参考**dynreg_dev_sample_动态注册.md**文档,介绍腾讯云物联网的设备接入认证以及动态注册功能。 22 | 23 | ## 广播通信 24 | 请参考**broadcast_sample_广播通信.md**文档,介绍腾讯云物联网的广播通信功能。 25 | 26 | ## 同步通信 27 | 请参考**rrpc_sample_同步通信.md**文档,介绍腾讯云物联网的同步通信功能。 28 | 29 | ## 设备日志上报功能 30 | 请参考**log_upload_设备日志上报.md**文档,介绍设备日志上报功能及使用 31 | 32 | ## CoAP通讯 33 | 请参考**coap_sample.md**文档,介绍腾讯云物联网的CoAP协议通信功能 34 | 35 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/system_mqtt_ssh_proxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef SYSTEM_MQTT_SSH_PROXY_H_ 17 | #define SYSTEM_MQTT_SSH_PROXY_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | int IOT_Ssh_state_report(void *pClient, int state); 24 | 25 | void IOT_QCLOUD_SSH_Start(void *mqtt_client); 26 | 27 | void IOT_QCLOUD_SSH_Stop(); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* SYSTEM_MQTT_SSH_PROXY_H_ */ -------------------------------------------------------------------------------- /external_libs/mbedtls/configs/README.txt: -------------------------------------------------------------------------------- 1 | This directory contains example configuration files. 2 | 3 | The examples are generally focused on a particular usage case (eg, support for 4 | a restricted number of ciphersuites) and aim at minimizing resource usage for 5 | this target. They can be used as a basis for custom configurations. 6 | 7 | These files are complete replacements for the default config.h. To use one of 8 | them, you can pick one of the following methods: 9 | 10 | 1. Replace the default file include/mbedtls/config.h with the chosen one. 11 | (Depending on your compiler, you may need to ajust the line with 12 | #include "mbedtls/check_config.h" then.) 13 | 14 | 2. Define MBEDTLS_CONFIG_FILE and adjust the include path accordingly. 15 | For example, using make: 16 | 17 | CFLAGS="-I$PWD/configs -DMBEDTLS_CONFIG_FILE=''" make 18 | 19 | Or, using cmake: 20 | 21 | find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} + 22 | CFLAGS="-I$PWD/configs -DMBEDTLS_CONFIG_FILE=''" cmake . 23 | make 24 | 25 | Note that the second method also works if you want to keep your custom 26 | configuration file outside the mbed TLS tree. 27 | -------------------------------------------------------------------------------- /platform/at_device/esp8266/at_device_esp8266.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef __AT_DEVICE_ESP8266_H__ 17 | #define __AT_DEVICE_ESP8266_H__ 18 | 19 | #define AT_RESP_TIMEOUT_MS (5000) 20 | #define ESP8266_SEND_MAX_LEN_ONCE (2048) 21 | #define ESP8266_MAX_SOCKET_NUM (5) 22 | 23 | #define WIFI_SSID "youga_wifi" //"Honor 8"// 24 | #define WIFI_PASSWORD "Iot@2018" //"xy123123"// 25 | 26 | int at_device_esp8266_init(void); 27 | 28 | #endif /* __AT_DEVICE_ESP8266_H__ */ 29 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_hmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_HMAC_H_ 17 | #define QCLOUD_IOT_UTILS_HMAC_H_ 18 | 19 | #include 20 | 21 | void utils_hmac_md5(const char *msg, int msg_len, char *digest, const char *key, int key_len); 22 | 23 | void utils_hmac_sha1(const char *msg, int msg_len, char *digest, const char *key, int key_len); 24 | 25 | int utils_hmac_sha1_hex(const char *msg, int msg_len, char *digest, const char *key, int key_len); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/mqtt_client_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_MQTT_CLIENT_NET_H_ 17 | #define IOT_MQTT_CLIENT_NET_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "network_interface.h" 24 | 25 | /** 26 | * @brief Init network stack 27 | * 28 | * @param pNetwork 29 | * @param pConnectParams 30 | * @return 0 for success 31 | */ 32 | int qcloud_iot_mqtt_network_init(Network *pNetwork); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // IOT_MQTT_CLIENT_NET_H_ 39 | -------------------------------------------------------------------------------- /sdk_src/protocol/coap/coap_client_net.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "coap_client_net.h" 21 | 22 | #include "network_interface.h" 23 | 24 | int qcloud_iot_coap_network_init(Network *pNetwork) 25 | { 26 | int rc; 27 | /* first choice: TLS */ 28 | pNetwork->type = NETWORK_DTLS; 29 | 30 | #ifdef AUTH_WITH_NOTLS 31 | pNetwork->type = NETWORK_UDP; 32 | #endif 33 | 34 | rc = network_init(pNetwork); 35 | 36 | return rc; 37 | } 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/ota_fetch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_OTA_FETCH_H_ 17 | #define IOT_OTA_FETCH_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | void *ofc_Init(const char *url, uint32_t offset, uint32_t size); 26 | 27 | int32_t qcloud_ofc_connect(void *handle); 28 | 29 | int32_t qcloud_ofc_fetch(void *handle, char *buf, uint32_t buf_len, uint32_t timeout_s); 30 | 31 | int qcloud_ofc_deinit(void *handle); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* IOT_OTA_FETCH_H_ */ 38 | -------------------------------------------------------------------------------- /platform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # src platform 2 | file(GLOB src_os ./os/${PLATFORM}/*.c ) 3 | set(src_platform ${src_os}) 4 | 5 | if(${FEATURE_AUTH_WITH_NOTLS} STREQUAL "OFF") 6 | file(GLOB src_platform_tls ./tls/mbedtls/*.c) 7 | list(APPEND src_platform ${src_platform_tls}) 8 | endif() 9 | 10 | if(AT_TCP_ENABLED STREQUAL "OFF") 11 | file(GLOB src_os ./os/${PLATFORM}/HAL_AT*.c) 12 | list(REMOVE_ITEM src_platform ${src_os}) 13 | endif() 14 | 15 | if(${EXTRACT_SRC} STREQUAL "ON") 16 | file(COPY ${src_platform} DESTINATION ${PROJECT_SOURCE_DIR}/output/qcloud_iot_c_sdk/platform/) 17 | endif() 18 | 19 | # src at_device 20 | if(AT_TCP_ENABLED STREQUAL "ON") 21 | file(GLOB src_at_device ./at_device/${AT_DEVICE_NAME}/*.c) 22 | endif() 23 | 24 | if(AT_TCP_ENABLED STREQUAL "ON" AND ${EXTRACT_SRC} STREQUAL "ON") 25 | file(COPY ${src_at_device} DESTINATION ${PROJECT_SOURCE_DIR}/output/qcloud_iot_c_sdk/platform/) 26 | endif() 27 | 28 | # target 29 | set(platform_target "iot_platform") 30 | 31 | # add library 32 | SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/lib/) 33 | if(AT_TCP_ENABLED STREQUAL "ON") 34 | add_library(${platform_target} STATIC ${src_platform} ${src_at_device}) 35 | else() 36 | add_library(${platform_target} STATIC ${src_platform}) 37 | endif() 38 | -------------------------------------------------------------------------------- /external_libs/mbedtls/include/mbedtls/net.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file net.h 3 | * 4 | * \brief Deprecated header file that includes mbedtls/net_sockets.h 5 | * 6 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | * 23 | * \deprecated Superseded by mbedtls/net_sockets.h 24 | */ 25 | 26 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) 27 | #include "mbedtls/net_sockets.h" 28 | #if defined(MBEDTLS_DEPRECATED_WARNING) 29 | #warning "Deprecated header file: Superseded by mbedtls/net_sockets.h" 30 | #endif /* MBEDTLS_DEPRECATED_WARNING */ 31 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 32 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/includes/Makefile.am: -------------------------------------------------------------------------------- 1 | # Wslay - The WebSocket Library 2 | 3 | # Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | nobase_include_HEADERS = wslay/wslay.h wslay/wslayver.h 24 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_BASE64_H_ 17 | #define QCLOUD_IOT_UTILS_BASE64_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #include "qcloud_iot_export_error.h" 26 | #include "qcloud_iot_export_log.h" 27 | 28 | int qcloud_iot_utils_base64encode(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen); 29 | 30 | int qcloud_iot_utils_base64decode(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | #endif /* QCLOUD_IOT_UTILS_BASE64_H_ */ 36 | -------------------------------------------------------------------------------- /external_libs/wslay/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake_minimum_required(VERSION 2.8) 2 | 3 | # This CMakeLists.txt file intended for: 4 | # - development of wslay library 5 | # - building wslay for install purposes 6 | # - building wslay with ExternalProject_Add() 7 | 8 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) 9 | if(NOT DEFINED CMAKE_BUILD_TYPE) 10 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") 11 | endif() 12 | 13 | option(WSLAY_CONFIGURE_INSTALL "Generate install target" ON) 14 | option(WSLAY_STATIC "Build static version of the library" ON) 15 | option(WSLAY_SHARED "Build shared version of the library" OFF) 16 | option(WSLAY_EXAMPLES "Build examples" OFF) 17 | option(WSLAY_TESTS "Build tests" OFF) 18 | 19 | SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/lib/) 20 | add_subdirectory(lib) 21 | 22 | if(WSLAY_EXAMPLES) 23 | add_subdirectory(examples) 24 | endif() 25 | if(WSLAY_TESTS) 26 | enable_testing() 27 | add_subdirectory(tests) 28 | endif() 29 | 30 | if (WSLAY_CONFIGURE_INSTALL) 31 | include(GNUInstallDirs) 32 | set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/wslay) 33 | # install(EXPORT wslay 34 | # DESTINATION ${INSTALL_CMAKE_DIR}) 35 | # configure_file(wslay-config.cmake.in wslay-config.cmake @ONLY) 36 | # install(FILES ${CMAKE_CURRENT_BINARY_DIR}/wslay-config.cmake 37 | # DESTINATION ${INSTALL_CMAKE_DIR}) 38 | endif() 39 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../tools/build_scripts/internal_make_funcs.mk 2 | 3 | # if were running on Windows build for Windows 4 | ifdef WINDOWS 5 | WINDOWS_BUILD=1 6 | endif 7 | 8 | # To compile as a shared library: 9 | ifdef SHARED 10 | # all code is position-indep with mingw, avoid warning about useless flag 11 | ifndef WINDOWS_BUILD 12 | LOCAL_CFLAGS += -fPIC -fpic -I./ 13 | endif 14 | endif 15 | 16 | DLEXT=so 17 | # OSX shared library extension: 18 | # DLEXT=dylib 19 | 20 | # Windows shared library extension: 21 | ifdef WINDOWS_BUILD 22 | DLEXT=dll 23 | endif 24 | 25 | OBJS= wslay_event.o wslay_frame.o wslay_net.o \ 26 | wslay_queue.o wslay_stack.o 27 | 28 | .SILENT: 29 | 30 | .PHONY: all static shared clean 31 | 32 | ifndef SHARED 33 | all: static 34 | else 35 | all: shared static 36 | endif 37 | 38 | static: libwslay.a 39 | 40 | shared: libwslay.$(DLEXT) 41 | 42 | libwslay.a: $(OBJS) 43 | $(call AR_Log) 44 | $(AR) -rc $@ $(OBJS) 45 | $(AR) -s $@ 46 | 47 | libwslay.$(DLEXT): $(OBJS) 48 | echo " LD $@" 49 | $(CC) -shared -Wl,-soname,$@ $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS) 50 | 51 | .c.o: 52 | # echo "[CC] $@ $<" 53 | $(call CC_Log) 54 | @ \ 55 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $< 56 | 57 | clean: 58 | ifndef WINDOWS 59 | rm -f *.o libwslay* 60 | else 61 | del /Q /F *.o libwslay* 62 | endif 63 | -------------------------------------------------------------------------------- /docs/MCU+腾讯云定制AT模组.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 腾讯云物联网提供了专用的 [腾讯云IoT AT指令集](https://github.com/tencentyun/qcloud-iot-sdk-tencent-at-based/blob/master/docs/%E8%85%BE%E8%AE%AF%E4%BA%91IoT%20AT%E6%8C%87%E4%BB%A4%E9%9B%86-V3.1.3.pdf),如果通讯模组实现了该指令集,则设备接入和通讯更为简单,所需代码量更少,针对这种场景,请参考面向腾讯云定制AT模组专用的 [MCU AT SDK](https://github.com/tencentyun/qcloud-iot-sdk-tencent-at-based.git) 3 | 4 | 目前腾讯云和主流的模组厂商进行了深度合作,将SDK的核心协议已移植到模组中,模组对外封装统一的腾讯云AT指令。已支持腾讯云定制AT指令的模组列表如下: 5 | 6 | | 序号 | 模组商 | 模组型号 | 通信制式 | 固件版本 | 7 | | -------| ------------| -------------------|------------------|----------------| 8 | | 1 | 中移 | M5311 | NB-IoT | M5311_LV_MOD_BOM_R002_1901232019_0906 | 9 | | 2 | 中移 | M6315 | 2G | CMIOT_M6315_20180901_V10_EXT_20190827_152209 | 10 | | 3 | 中移 | M8321 | 4G | QCloud_AT_v3.0.1_4G_Cellular 20190909_171245 | 11 | | 4 | 有方 | N10 | 2G | N10_I_1187_PQS63010_TC_V002C | 12 | | 5 | 有方 | N21 | NB-IoT | N21_RDD0CM_TC_V006A | 13 | | 6 | 有方 | N720 | 4G | N720_EAB0CMF_BZ_V003A_T1 | 14 | | 7 | 移柯 | L206 | 2G | L206Dv01.04b04.04 | 15 | | 8 | 乐鑫 | ESP8266 | WIFI | QCloud_AT_ESP_WiFi_v1.1.0 | 16 | 17 | -------------------------------------------------------------------------------- /include/exports/qcloud_iot_export_dynreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QLCOUD_IOT_EXPORT_DYNREG_H_ 17 | #define QLCOUD_IOT_EXPORT_DYNREG_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "qcloud_iot_export.h" 24 | 25 | /** 26 | * @brief Do dynamic register/create device 27 | * 28 | * @param pDevInfo In: device info with [ProductId, ProductKey, DeviceName] 29 | * Out: device info with [ProductId, DeviceName, DeviceSecret or Device cert/key file] 30 | * 31 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 32 | */ 33 | int IOT_DynReg_Device(DeviceInfo *pDevInfo); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif // QLCOUD_IOT_EXPORT_DYNREG_H_ -------------------------------------------------------------------------------- /sdk_src/internal_inc/resource_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_RESOURCE_LIB_H_ 17 | #define IOT_RESOURCE_LIB_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | void qcloud_lib_md5_init(void *ctx_md5); 27 | 28 | void qcloud_lib_md5_update(void *md5, const char *buf, size_t buf_len); 29 | 30 | void qcloud_lib_md5_finish_tolowercasehex(void *md5, char *output_str); 31 | 32 | void qcloud_lib_md5_deinit(void *md5); 33 | 34 | int qcloud_lib_get_json_key_value(char *json_obj, char *json_key, char **value); 35 | 36 | int qcloud_lib_base64encode_md5sum(char *md5sumhex, char *outbase64, int outbase64len); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* IOT_RESOURCE_LIB_H_ */ 43 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/resource_upload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_RESOURCE_UPLOAD_H_ 17 | #define IOT_RESOURCE_UPLOAD_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | void *qcloud_resource_upload_http_init(const char *url, char *md5sum, int upload_len); 26 | 27 | int32_t qcloud_resource_upload_http_connect(void *handle); 28 | 29 | int32_t qcloud_resource_upload_http_send_body(void *handle, char *buf, uint32_t buf_len, uint32_t timeout_s); 30 | 31 | int32_t qcloud_resource_upload_http_recv(void *handle, char *buf, uint32_t bufLen, uint32_t timeout_s); 32 | 33 | int qcloud_resource_upload_http_deinit(void *handle); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* IOT_RESOURCE_UPLOAD_H_ */ 40 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/includes/wslay/wslayver.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAYVER_H 26 | #define WSLAYVER_H 27 | 28 | /* Version number of wslay release */ 29 | #define WSLAY_VERSION "@PACKAGE_VERSION@" 30 | 31 | #endif /* WSLAYVER_H */ 32 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/includes/wslay/wslayver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAYVER_H 26 | #define WSLAYVER_H 27 | 28 | /* Version number of wslay release */ 29 | #define WSLAY_VERSION "" 30 | 31 | #endif /* WSLAYVER_H */ 32 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_url_upload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 Tencent. All rights reserved. 5 | 6 | * Licensed under the MIT License (the "License"); you may not use this file 7 | except in 8 | * compliance with the License. You may obtain a copy of the License at 9 | * http://opensource.org/licenses/MIT 10 | 11 | * Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | KIND, 15 | * either express or implied. See the License for the specific language 16 | governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | #ifndef UTILS_URL_UPLOAD_H_ 22 | #define UTILS_URL_UPLOAD_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | void *qcloud_url_upload_init(const char *url, uint32_t content_len, char *custom_header); 31 | 32 | int32_t qcloud_url_upload_connect(void *handle, int method); 33 | 34 | int32_t qcloud_url_upload_body(void *handle, char *data_buf, uint32_t data_Len, uint32_t timeout_ms); 35 | 36 | int32_t qcloud_url_upload_recv_response(void *handle, char *response_buf, uint32_t bufLen, uint32_t timeout_ms); 37 | 38 | int qcloud_url_upload_deinit(void *handle); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* UTILS_URL_DOWNLOAD_H_ */ 45 | -------------------------------------------------------------------------------- /include/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef PLATFORM_H_ 17 | #define PLATFORM_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define PATH_MAX 4096 24 | /* Max size of cert/key file full path */ 25 | #define FILE_PATH_MAX_LEN 256 26 | 27 | #ifdef WIN32 28 | #include 29 | #include 30 | #include 31 | #include 32 | typedef signed long ssize_t; 33 | #define getcwd(buffer, len) _getcwd(buffer, len) 34 | #endif 35 | 36 | #if defined(__linux__) && defined(__GLIBC__) 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* PLATFORM_H_ */ 52 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/qcloud_iot_ca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_CA_H_ 17 | #define IOT_CA_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | const char *iot_ca_get(void); 24 | 25 | const char *iot_dynreg_https_ca_get(void); 26 | 27 | const char *iot_https_ca_get(void); 28 | 29 | const char *iot_wss_ssh_ca_get(void); 30 | 31 | const char *iot_wss_mqtt_ca_get(void); 32 | 33 | const char *iot_get_mqtt_domain(const char *region); 34 | 35 | int iot_get_mqtt_port(void); 36 | 37 | const char *iot_get_coap_domain(const char *region); 38 | 39 | const char *iot_get_dyn_reg_domain(const char *region); 40 | 41 | const char *iot_get_ws_ssh_domain(const char *region); 42 | 43 | const char *iot_get_ssh_domain(const char *region); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* IOT_CA_H_ */ 50 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/wslay_net.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "wslay_net.h" 26 | 27 | #ifndef WORDS_BIGENDIAN 28 | 29 | uint64_t wslay_byteswap64(uint64_t x) 30 | { 31 | uint64_t u = ntohl(x & 0xffffffffllu); 32 | uint64_t l = ntohl(x >> 32); 33 | return (u << 32) | l; 34 | } 35 | 36 | #endif /* !WORDS_BIGENDIAN */ 37 | -------------------------------------------------------------------------------- /external_libs/mbedtls/library/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version information 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | 22 | #if !defined(MBEDTLS_CONFIG_FILE) 23 | #include "mbedtls/config.h" 24 | #else 25 | #include MBEDTLS_CONFIG_FILE 26 | #endif 27 | 28 | #if defined(MBEDTLS_VERSION_C) 29 | 30 | #include "mbedtls/version.h" 31 | #include 32 | 33 | unsigned int mbedtls_version_get_number() 34 | { 35 | return( MBEDTLS_VERSION_NUMBER ); 36 | } 37 | 38 | void mbedtls_version_get_string( char *string ) 39 | { 40 | memcpy( string, MBEDTLS_VERSION_STRING, 41 | sizeof( MBEDTLS_VERSION_STRING ) ); 42 | } 43 | 44 | void mbedtls_version_get_string_full( char *string ) 45 | { 46 | memcpy( string, MBEDTLS_VERSION_STRING_FULL, 47 | sizeof( MBEDTLS_VERSION_STRING_FULL ) ); 48 | } 49 | 50 | #endif /* MBEDTLS_VERSION_C */ 51 | -------------------------------------------------------------------------------- /platform/os/windows/HAL_AT_UART_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #include "qcloud_iot_export.h" 17 | #include "qcloud_iot_import.h" 18 | 19 | #ifdef AT_TCP_ENABLED 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "at_client.h" 27 | #include "utils_ringbuff.h" 28 | 29 | /** 30 | * @brief This function handles AT UART global interrupt,push recv char to ringbuff. 31 | */ 32 | void HAL_AT_UART_IRQHandler(void) {} 33 | 34 | /** 35 | *pdata: pointer of data for send 36 | *len: len of data to be sent 37 | *return: the len of data send success 38 | * @brief hal api for at data send 39 | */ 40 | int HAL_AT_Uart_Send(void *data, uint32_t size) 41 | { 42 | return 0; 43 | } 44 | 45 | int HAL_AT_Uart_Init(void) 46 | { 47 | return QCLOUD_RET_SUCCESS; 48 | } 49 | 50 | int HAL_AT_Uart_Deinit(void) 51 | { 52 | return QCLOUD_RET_SUCCESS; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/exports/qcloud_iot_export_broadcast.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_EXPORT_BROADCAST_H_ 17 | #define QCLOUD_IOT_EXPORT_BROADCAST_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #ifdef BROADCAST_ENABLED 26 | 27 | /** 28 | * @brief broadcast message callback 29 | */ 30 | typedef void (*OnBroadcastMessageCallback)(void *pClient, const char *msg, uint32_t msgLen); 31 | 32 | /** 33 | * @brief Subscribe broadcast topic with message callback 34 | * 35 | * @param pClient pointer of handle to MQTT client 36 | * @param callback Broadcast message callback 37 | * @return QCLOUD_RET_SUCCESS when success, otherwise fail 38 | */ 39 | int IOT_Broadcast_Subscribe(void *pClient, OnBroadcastMessageCallback callback); 40 | 41 | #endif 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // QCLOUD_IOT_EXPORT_BROADCAST_H_ 48 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_websocket_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef UTILS_WEBSOCKET_CLIENT_H_ 17 | #define UTILS_WEBSOCKET_CLIENT_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct { 24 | void *userdata; 25 | void (*recv_data_err)(void *iotwsctx); 26 | void (*send_data_err)(void *iotwsctx); 27 | void (*proc_recv_msg_callback)(char *data, int datalen, void *iotwsctx); 28 | void * wslay_ctx; 29 | Network network_stack; 30 | } UtilsIotWSClientCtx; 31 | 32 | int Utils_WSClient_connect(const char *protocol, UtilsIotWSClientCtx *ctx, const char *ws_custom_header); 33 | int Utils_WSClient_send(UtilsIotWSClientCtx *ctx, char *data, int data_len); 34 | int Utils_WSClient_recv(UtilsIotWSClientCtx *ctx); 35 | void Utils_WSClient_disconn(UtilsIotWSClientCtx *ctx); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* UTILS_WEBSOCKET_CLIENT_H_ */ -------------------------------------------------------------------------------- /sdk_src/internal_inc/at_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef _AT_UTILS_H_ 17 | #define _AT_UTILS_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #define WIDTH_SIZE 32 24 | 25 | #ifndef __INT_MAX__ 26 | #define __INT_MAX__ 2147483647 27 | #endif 28 | 29 | #ifndef INT_MAX 30 | #define INT_MAX (__INT_MAX__) 31 | #endif 32 | 33 | #define AT_CMD_COMMA_MARK ',' 34 | #define AT_CMD_DQUOTES_MARK '"' 35 | 36 | #define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ') 37 | 38 | int at_vprintfln(const char *format, va_list args); 39 | void at_print_raw_cmd(const char *name, const char *cmd, int size); 40 | const char *at_get_last_cmd(int *cmd_size); 41 | int at_req_parse_args(const char *req_args, const char *req_expr, ...); 42 | int at_sscanf(const char *buf, const char *fmt, va_list args); 43 | void at_strip(char *str, const char patten); 44 | void chr_strip(char *str, const char patten); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_ringbuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef __AT_RING_BUFF_H__ 17 | #define __AT_RING_BUFF_H__ 18 | 19 | #include "stdbool.h" 20 | #include "stdint.h" 21 | 22 | #define RINGBUFF_OK 0 /* No error, everything OK. */ 23 | #define RINGBUFF_ERR -1 /* Out of memory error. */ 24 | #define RINGBUFF_EMPTY -3 /* Timeout. */ 25 | #define RINGBUFF_FULL -4 /* Routing problem. */ 26 | #define RINGBUFF_TOO_SHORT -5 27 | 28 | typedef struct _ring_buff_ { 29 | uint32_t size; 30 | uint32_t readpoint; 31 | uint32_t writepoint; 32 | char* buffer; 33 | bool full; 34 | } sRingbuff; 35 | 36 | typedef sRingbuff* ring_buff_t; 37 | 38 | int ring_buff_init(sRingbuff* ring_buff, char* buff, uint32_t size); 39 | int ring_buff_flush(sRingbuff* ring_buff); 40 | int ring_buff_push_data(sRingbuff* ring_buff, uint8_t* pData, int len); 41 | int ring_buff_pop_data(sRingbuff* ring_buff, uint8_t* pData, int len); 42 | #endif // __ringbuff_h__ 43 | -------------------------------------------------------------------------------- /tools/update_from_old_SDK.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | sed -i "s/QCLOUD_ERR_SUCCESS/QCLOUD_RET_SUCCESS/g" `grep -rwl QCLOUD_ERR_SUCCESS ./*` 4 | sed -i "s/QCLOUD_ERR_MQTT_RECONNECTED/QCLOUD_RET_MQTT_RECONNECTED/g" `grep -rwl QCLOUD_ERR_MQTT_RECONNECTED ./*` 5 | sed -i "s/QCLOUD_ERR_MQTT_MANUALLY_DISCONNECTED/QCLOUD_RET_MQTT_MANUALLY_DISCONNECTED/g" `grep -rwl QCLOUD_ERR_MQTT_MANUALLY_DISCONNECTED ./*` 6 | sed -i "s/QCLOUD_ERR_MQTT_CONNACK_CONNECTION_ACCEPTED/QCLOUD_RET_MQTT_CONNACK_CONNECTION_ACCEPTED/g" `grep -rwl QCLOUD_ERR_MQTT_CONNACK_CONNECTION_ACCEPTED ./*` 7 | sed -i "s/QCLOUD_ERR_MQTT_ALREADY_CONNECTED/QCLOUD_RET_MQTT_ALREADY_CONNECTED/g" `grep -rwl QCLOUD_ERR_MQTT_ALREADY_CONNECTED ./*` 8 | sed -i "s/MAX_SIZE_OF_DEVICE_SERC/MAX_SIZE_OF_DEVICE_SECRET/g" `grep -rwl MAX_SIZE_OF_DEVICE_SERC ./*` 9 | sed -i "s/devCertFileName/dev_cert_file_name/g" `grep -rwl devCertFileName ./*` 10 | sed -i "s/devPrivateKeyFileName/dev_key_file_name/g" `grep -rwl devPrivateKeyFileName ./*` 11 | sed -i "s/devSerc/device_secret/g" `grep -rwl devSerc ./*` 12 | sed -i "s/MAX_SIZE_OF_PRODUCT_KEY/MAX_SIZE_OF_PRODUCT_SECRET/g" `grep -rwl MAX_SIZE_OF_PRODUCT_KEY ./*` 13 | sed -i "s/product_key/product_secret/g" `grep -rwl product_key ./*` 14 | sed -i "s/DEBUG/eLOG_DEBUG/g" `grep -rwl DEBUG ./*` 15 | sed -i "s/INFO/eLOG_INFO/g" `grep -rwl INFO ./*` 16 | sed -i "s/WARN/eLOG_WARN/g" `grep -rwl WARN ./*` 17 | sed -i "s/ERROR/eLOG_ERROR/g" `grep -rwl ERROR ./*` 18 | sed -i "s/DISABLE/eLOG_DISABLE/g" `grep -rwl DISABLE ./*` 19 | sed -i "s/Log_writter/IOT_Log_Gen/g" `grep -rwl Log_writter ./*` 20 | sed -i "s/qcloud_iot_dyn_reg_dev/IOT_DynReg_Device/g" `grep -rwl qcloud_iot_dyn_reg_dev ./*` 21 | sed -i "s/IOT_SYSTEM_GET_TIME/IOT_Get_SysTime/g" `grep -rwl IOT_SYSTEM_GET_TIME ./*` 22 | 23 | -------------------------------------------------------------------------------- /sdk_src/protocol/mqtt/mqtt_client_net.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "mqtt_client_net.h" 21 | 22 | // TODO: how to implement 23 | /** 24 | * @brief Check if TLS connection is valid 25 | * 26 | * @param pNetwork 27 | * @return 28 | */ 29 | int qcloud_iot_mqtt_tls_is_connected(Network *pNetwork) 30 | { 31 | return 1; 32 | } 33 | 34 | /** 35 | * @brief Init network stack 36 | * 37 | * @param pNetwork 38 | * @param pConnectParams 39 | * @return 40 | */ 41 | int qcloud_iot_mqtt_network_init(Network *pNetwork) 42 | { 43 | int rc; 44 | 45 | /* first choice: TLS */ 46 | pNetwork->type = NETWORK_TLS; 47 | 48 | #ifdef AUTH_WITH_NOTLS 49 | pNetwork->type = NETWORK_TCP; 50 | #endif 51 | 52 | #ifdef WEBSOCKET_MQTT 53 | pNetwork->type = NETWORK_WS_MQTT; 54 | #endif 55 | 56 | rc = network_init(pNetwork); 57 | pNetwork->is_connected = qcloud_iot_mqtt_tls_is_connected; 58 | 59 | return rc; 60 | } 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /include/exports/qcloud_iot_export_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_EXPORT_SYSTEM_H_ 17 | #define QCLOUD_IOT_EXPORT_SYSTEM_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * @brief Get system timestamp from MQTT server 25 | * 26 | * @param pClient MQTTClient pointer 27 | * @param time timestamp value return from server 28 | * @return QCLOUD_RET_SUCCESS for success 29 | * otherwise, failure 30 | */ 31 | int IOT_Get_SysTime(void* pClient, long* time); 32 | 33 | /** 34 | * @brief sync ntp timestamp from MQTT server 35 | * 36 | * @param pClient MQTTClient pointer 37 | * @return QCLOUD_RET_SUCCESS for success 38 | * otherwise, failure 39 | */ 40 | int IOT_Sync_NTPTime(void* pClient); 41 | 42 | /** 43 | * @brief enable mqtt ssh, subscribe topic 44 | * 45 | * @param pClient MQTTClient pointer 46 | * @return QCLOUD_RET_SUCCESS for success 47 | * otherwise, failure 48 | */ 49 | int IOT_Ssh_enable(void* pClient); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* QCLOUD_IOT_EXPORT_COAP_H_ */ -------------------------------------------------------------------------------- /docs/en/MCU+Tencent Cloud IoT AT instruction_EN-US.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | IoT Hub provides a dedicated [Tencent Cloud IoT AT instruction set](https://github.com/tencentyun/qcloud-iot-sdk-tencent-at-based/blob/master/docs/%E8%85%BE%E8%AE%AF%E4%BA%91IoT%20AT%E6%8C%87%E4%BB%A4%E9%9B%86-V3.1.3.pdf). If the communication module implements this instruction set, it will be easier for devices to connect and communicate, and less code will be required. For this scenario, please refer to the [SDK for MCU AT](https://github.com/tencentyun/qcloud-iot-sdk-tencent-at-based.git) dedicated to the Tencent Cloud customized AT module. 3 | 4 | Currently, Tencent Cloud works closely with major module vendors to port the core protocols of the SDK to modules, which encapsulate unified Tencent Cloud AT instructions. The modules that support Tencent Cloud customized AT instructions are as listed below: 5 | 6 | | No. | Module Vendor | Module Model | Communication Standard | Firmware Version | 7 | | -------| ------------| -------------------|------------------|----------------| 8 | | 1 | China Mobile | M5311 | NB-IoT | M5311_LV_MOD_BOM_R002_1901232019_0906 | 9 | | 2 | China Mobile | M6315 | 2G | CMIOT_M6315_20180901_V10_EXT_20190827_152209 | 10 | | 3 | China Mobile | M8321 | 4G | QCloud_AT_v3.0.1_4G_Cellular 20190909_171245 | 11 | | 4 | Neoway | N10 | 2G | N10_I_1187_PQS63010_TC_V002C | 12 | | 5 | Neoway | N21 | NB-IoT | N21_RDD0CM_TC_V006A | 13 | | 6 | Neoway | N720 | 4G | N720_EAB0CMF_BZ_V003A_T1 | 14 | | 7 | MobileTek | L206 | 2G | L206Dv01.04b04.04 | 15 | | 8 | Espressif | ESP8266 | Wi-Fi | QCloud_AT_ESP_WiFi_v1.1.0 | 16 | 17 | -------------------------------------------------------------------------------- /docs/MCU+通用TCP_AT模组移植(FreeRTOS).md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | 对于不具备网络通讯能力的MCU,一般采用MCU+通讯模组的方式,通讯模组(包括WiFi/2G/4G/NB-IoT)一般提供了基于串口的AT指令协议供MCU进行网络通讯。针对这种场景,C-SDK 封装了AT-socket网络层,网络层之上的核心协议和服务层无须移植。本文阐述针对 MCU(FreeRTOS)+通用TCP AT模组的目标环境,如何移植C-SDK 并接入腾讯云物联网平台。 4 | 5 | ## 移植步骤 6 | 7 | ### 1. 下载最新版本设备端 [C-SDK](https://github.com/tencentyun/qcloud-iot-sdk-embedded-c)。 8 | 9 | ### 2. SDK功能配置及代码抽取 10 | - 使用通用TCP模组编译配置选项配置如下: 11 | 12 | | 名称 | 配置 | 说明 | 13 | | :------------------------------- | ------------- | ------------------------------------------------------------ | 14 | | BUILD_TYPE | debug/release | 根据需要设置 | 15 | | EXTRACT_SRC | ON | 使能代码抽取 | 16 | | COMPILE_TOOLS | gcc/MSVC | 根据需要设置,IDE情况不关注 | 17 | | PLATFORM | linux/windows | 根据需要设置,IDE情况不关注 | 18 | | FEATURE_OTA_COMM_ENABLED | ON/OFF | 根据需要设置 | 19 | | FEATURE_AUTH_MODE | KEY | 资源受限设备认证方式建议选秘钥认证 | 20 | | FEATURE_AUTH_WITH_NOTLS | ON/OFF | 根据需要是否使能TLS | 21 | | FEATURE_AT_TCP_ENABLED | ON | AT模组TCP功能开关 | 22 | | FEATURE_AT_UART_RECV_IRQ | ON | AT模组中断接受功能开关 | 23 | | FEATURE_AT_OS_USED | ON | AT模组多线程功能开关 | 24 | | FEATURE_AT_DEBUG | OFF | 默认关闭AT模组调试功能,有调试需要再打开| 25 | 26 | - 参考文档[C-SDK_Build编译环境及配置选项说明]()抽取代码 27 | 28 | ### 3. HAL 层移植 29 | 30 | 参见[C-SDK_Porting跨平台移植概述]() 31 | 对于网络相关的HAL接口,通过上面的编译选项已选择SDK提供的AT_Socket框架,SDK会调用 network_at_tcp.c 的at_socket接口,at_socket层不需要移植,需要实现AT串口驱动及AT模组驱动,AT模组驱动只需要实现AT框架中at_device的驱动结构体 *at_device_op_t* 的驱动接口即可,可以参照at_device目录下的已支持的模组。目前SDK针对物联网使用较广的WiFi模组ESP8266提供了底层接口实现,供移植到其他通讯模组时作为参考。 32 | 33 | ### 4. 业务逻辑开发 34 | 35 | 对于IoT_Hub产品,可以参考Docs/IoT_Hub目录下的例程。 36 | 37 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/ota_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_OTA_CLIENT_H_ 17 | #define IOT_OTA_CLIENT_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | /* Specify the maximum characters of version */ 26 | #define OTA_MAX_TOPIC_LEN (64) 27 | 28 | #define TYPE_FIELD "type" 29 | #define MD5_FIELD "md5sum" 30 | #define VERSION_FIELD "version" 31 | #define URL_FIELD "url" 32 | #define FILESIZE_FIELD "file_size" 33 | #define RESULT_FIELD "result_code" 34 | 35 | #define REPORT_VERSION_RSP "report_version_rsp" 36 | #define UPDATE_FIRMWARE "update_firmware" 37 | 38 | enum { MQTT_CHANNEL, COAP_CHANNEL }; 39 | 40 | typedef void (*OnOTAMessageCallback)(void *pcontext, const char *msg, uint32_t msgLen); 41 | 42 | void *qcloud_osc_init(const char *productId, const char *deviceName, void *channel, OnOTAMessageCallback callback, 43 | void *context); 44 | 45 | int qcloud_osc_deinit(void *handle); 46 | 47 | int qcloud_osc_report_progress(void *handle, const char *msg); 48 | 49 | int qcloud_osc_report_version(void *handle, const char *msg); 50 | 51 | int qcloud_osc_report_upgrade_result(void *handle, const char *msg); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif /* IOT_OTA_CLIENT_H_ */ 58 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/wslay_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAY_NET_H 26 | #define WSLAY_NET_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | #ifdef HAVE_ARPA_INET_H 35 | #include 36 | #endif /* HAVE_ARPA_INET_H */ 37 | #ifdef HAVE_NETINET_IN_H 38 | #include 39 | #endif /* HAVE_NETINET_IN_H */ 40 | /* For Mingw build */ 41 | #ifdef HAVE_WINSOCK2_H 42 | #include 43 | #endif /* HAVE_WINSOCK2_H */ 44 | 45 | #ifdef WORDS_BIGENDIAN 46 | #define ntoh64(x) (x) 47 | #define hton64(x) (x) 48 | #else /* !WORDS_BIGENDIAN */ 49 | uint64_t wslay_byteswap64(uint64_t x); 50 | #define ntoh64(x) wslay_byteswap64(x) 51 | #define hton64(x) wslay_byteswap64(x) 52 | #endif /* !WORDS_BIGENDIAN */ 53 | 54 | #endif /* WSLAY_NET_H */ 55 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/wslay_stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAY_STACK_H 26 | #define WSLAY_STACK_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | struct wslay_stack_cell { 35 | void * data; 36 | struct wslay_stack_cell *next; 37 | }; 38 | 39 | struct wslay_stack { 40 | struct wslay_stack_cell *top; 41 | }; 42 | 43 | struct wslay_stack *wslay_stack_new(); 44 | void wslay_stack_free(struct wslay_stack *stack); 45 | int wslay_stack_push(struct wslay_stack *stack, void *data); 46 | void wslay_stack_pop(struct wslay_stack *stack); 47 | void * wslay_stack_top(struct wslay_stack *stack); 48 | int wslay_stack_empty(struct wslay_stack *stack); 49 | 50 | #endif /* WSLAY_STACK_H */ 51 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/shadow_client_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_SHADOW_CLIENT_COMMON_H_ 17 | #define IOT_SHADOW_CLIENT_COMMON_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "shadow_client.h" 24 | 25 | /** 26 | * @brief register a device property 27 | * 28 | * @param pShadow shadow client 29 | * @param pProperty device property 30 | * @param callback callback when property changes 31 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 32 | */ 33 | int shadow_common_register_property_on_delta(Qcloud_IoT_Shadow *pShadow, DeviceProperty *pProperty, 34 | OnPropRegCallback callback); 35 | 36 | /** 37 | * @brief remove a device property 38 | * 39 | * @param pShadow shadow client 40 | * @param pProperty device property 41 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 42 | */ 43 | int shadow_common_remove_property(Qcloud_IoT_Shadow *pshadow, DeviceProperty *pProperty); 44 | 45 | /** 46 | * @brief check if a device property exists 47 | * 48 | * @param pShadow shadow client 49 | * @param pProperty device property 50 | * @return 0 = not existed 51 | */ 52 | int shadow_common_check_property_existence(Qcloud_IoT_Shadow *pshadow, DeviceProperty *pProperty); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // IOT_SHADOW_CLIENT_COMMON_H_ 59 | -------------------------------------------------------------------------------- /external_libs/mbedtls/include/mbedtls/havege.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file havege.h 3 | * 4 | * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_HAVEGE_H 24 | #define MBEDTLS_HAVEGE_H 25 | 26 | #include 27 | 28 | #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief HAVEGE state structure 36 | */ 37 | typedef struct 38 | { 39 | int PT1, PT2, offset[2]; 40 | int pool[MBEDTLS_HAVEGE_COLLECT_SIZE]; 41 | int WALK[8192]; 42 | } 43 | mbedtls_havege_state; 44 | 45 | /** 46 | * \brief HAVEGE initialization 47 | * 48 | * \param hs HAVEGE state to be initialized 49 | */ 50 | void mbedtls_havege_init( mbedtls_havege_state *hs ); 51 | 52 | /** 53 | * \brief Clear HAVEGE state 54 | * 55 | * \param hs HAVEGE state to be cleared 56 | */ 57 | void mbedtls_havege_free( mbedtls_havege_state *hs ); 58 | 59 | /** 60 | * \brief HAVEGE rand function 61 | * 62 | * \param p_rng A HAVEGE state 63 | * \param output Buffer to fill 64 | * \param len Length of buffer 65 | * 66 | * \return 0 67 | */ 68 | int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len ); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* havege.h */ 75 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/resource_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_RESOURCE_CLIENT_H_ 17 | #define IOT_RESOURCE_CLIENT_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #include "qcloud_iot_export_resource.h" 26 | 27 | enum { MQTT_CHANNEL }; 28 | 29 | typedef struct qcloud_resource_upload_request { 30 | int resource_size; 31 | char *resource_name; 32 | char *resource_md5sum; 33 | } QCLOUD_RESOURCE_UPLOAD_REQUEST_S; 34 | 35 | typedef void (*OnResourceMessageCallback)(void *pcontext, char *msg, uint32_t msgLen); 36 | 37 | void *qcloud_resource_mqtt_init(const char *productId, const char *deviceName, void *channel, 38 | OnResourceMessageCallback callback, void *context); 39 | 40 | int qcloud_resource_mqtt_deinit(void *resource_mqtt); 41 | 42 | int qcloud_resource_mqtt_yield(void *resource_mqtt); 43 | 44 | int qcloud_resource_mqtt_upload_request(void *resource_mqtt, void *request_data); 45 | 46 | int qcloud_resource_mqtt_download_get(void *resource_mqtt); 47 | 48 | int qcloud_resource_mqtt_report_progress(void *resource_mqtt, QCLOUD_RESOURCE_REPORT_E state, 49 | QCLOUD_RESOURCE_RESULTCODE_E resultcode, int percent, char *resource_name, 50 | bool download); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* IOT_RESOURCE_CLIENT_H_ */ 57 | -------------------------------------------------------------------------------- /platform/os/nonos/HAL_OS_nonos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "qcloud_iot_import.h" 21 | #include "stm32l4xx_hal.h" 22 | 23 | void HAL_Printf(_IN_ const char *fmt, ...) 24 | { 25 | va_list args; 26 | 27 | va_start(args, fmt); 28 | vprintf(fmt, args); 29 | va_end(args); 30 | 31 | fflush(stdout); 32 | } 33 | 34 | int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...) 35 | { 36 | va_list args; 37 | int rc; 38 | 39 | va_start(args, fmt); 40 | rc = vsnprintf(str, len, fmt, args); 41 | va_end(args); 42 | 43 | return rc; 44 | } 45 | 46 | int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap) 47 | { 48 | return vsnprintf(str, len, format, ap); 49 | } 50 | 51 | void HAL_SleepMs(_IN_ uint32_t ms) 52 | { 53 | (void)HAL_Delay(ms); 54 | } 55 | 56 | void HAL_DelayMs(_IN_ uint32_t ms) 57 | { 58 | (void)HAL_Delay(ms); 59 | } 60 | 61 | void HAL_Free(void *ptr) 62 | { 63 | if (ptr) 64 | free(ptr); 65 | } 66 | 67 | void *HAL_Malloc(uint32_t size) 68 | { 69 | return malloc(size); 70 | } 71 | 72 | void *HAL_MutexCreate(void) 73 | { 74 | return (void *)1; 75 | } 76 | 77 | void HAL_MutexDestroy(void *mutex) 78 | { 79 | return; 80 | } 81 | 82 | void HAL_MutexLock(void *mutex) 83 | { 84 | return; 85 | } 86 | 87 | void HAL_MutexUnlock(void *mutex) 88 | { 89 | return; 90 | } 91 | -------------------------------------------------------------------------------- /docs/MCU+通用TCP_AT模组移植(nonOS).md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | 对于不具备网络通讯能力的MCU,一般采用MCU+通讯模组的方式,通讯模组(包括WiFi/2G/4G/NB-IoT)一般提供了基于串口的AT指令协议供MCU进行网络通讯。针对这种场景,C-SDK 封装了AT-socket网络层,网络层之上的核心协议和服务层无须移植。本文阐述针对 MCU(无OS)+通用TCP AT模组的目标环境,如何移植C-SDK 并接入腾讯云物联网平台。 4 | 相较于有RTOS场景,at_socket网络接收数据的处理会有差异,应用层需要周期性的调用**IOT_MQTT_Yield**来接收服务端下行数据,错过接收窗口则会存在数据丢失的情况,所以在业务逻辑较为复杂的场景建议使用RTOS,通过配置 FEATURE_AT_OS_USED = OFF选择无OS方式。 5 | 6 | ## 移植步骤 7 | 8 | ### 1. 下载最新版本设备端 [C-SDK](https://github.com/tencentyun/qcloud-iot-sdk-embedded-c)。 9 | 10 | ### 2. SDK功能配置及代码抽取 11 | - 无RTOS使用通用TCP模组编译配置选项配置如下: 12 | 13 | | 名称 | 配置 | 说明 | 14 | | :------------------------------- | ------------- | ------------------------------------------------------------ | 15 | | BUILD_TYPE | debug/release | 根据需要设置 | 16 | | EXTRACT_SRC | ON | 使能代码抽取 | 17 | | COMPILE_TOOLS | gcc/MSVC | 根据需要设置,IDE情况不关注 | 18 | | PLATFORM | linux/windows | 根据需要设置,IDE情况不关注 | 19 | | FEATURE_OTA_COMM_ENABLED | ON/OFF | 根据需要设置 | 20 | | FEATURE_AUTH_MODE | KEY | 资源受限设备认证方式建议选秘钥认证 | 21 | | FEATURE_AUTH_WITH_NOTLS | ON/OFF | 根据需要是否使能TLS | 22 | | FEATURE_AT_TCP_ENABLED | ON | 使能at_socket组件 | 23 | | FEATURE_AT_UART_RECV_IRQ | ON | 使能AT串口中断接收 | 24 | | FEATURE_AT_OS_USED | OFF | at_socket组件无RTOS环境使用 | 25 | | FEATURE_AT_DEBUG | OFF | 默认关闭AT模组调试功能,有调试需要再打开| 26 | 27 | - 参考文档[C-SDK_Build编译环境及配置选项说明]()抽取代码 28 | 29 | ### 3. HAL 层移植 30 | 31 | 参见[C-SDK_Porting跨平台移植概述]() 32 | 33 | 对于网络相关的HAL接口,通过上面的编译选项已选择SDK提供的AT_Socket框架,SDK会调用 network_at_tcp.c 的at_socket接口,at_socket层不需要移植,需要实现AT串口驱动及AT模组驱动,AT模组驱动只需要实现AT框架中at_device的驱动结构体 *at_device_op_t* 的驱动接口即可,可以参照at_device目录下的已支持的模组。AT串口驱动需要实现串口的中断接收,然后在中断服务程序中调用回调函数 *at_client_uart_rx_isr_cb* 即可,可以参考 HAL_OS_nonos.c 实现目标平台的移植。 34 | 35 | ### 4. 业务逻辑开发 36 | 37 | 可以参考Docs/IoT_Hub目录下的例程。 38 | 39 | -------------------------------------------------------------------------------- /docs/en/C-SDK Multi-Thread and Multi-Device Support_EN-US.md: -------------------------------------------------------------------------------- 1 | # C-SDK Multi-Thread and Multi-Device Support 2 | 3 | To support multi-thread and multi-device instances, you need to enable the compilation configuration item `FEATURE_MULTITHREAD_ENABLED` first. 4 | 5 | ## Notes on Use in Multithreaded Environment 6 | 7 | The device C-SDK can be used in a multithreaded and multitasking environment, but there are certain specifications for the use of APIs. 8 | For example, to use MQTT APIs in a multithreaded environment, you need to pay attention to the following: 9 | ``` 10 | 1. You cannot use multiple threads to call `IOT_MQTT_Yield`, `IOT_MQTT_Construct`, or `IOT_MQTT_Destroy`. 11 | 2. You can use multiple threads to call `IOT_MQTT_Publish`, `IOT_MQTT_Subscribe`, and `IOT_MQTT_Unsubscribe`. 12 | 3. As the function to read MQTT messages from `socket` and process them, `IOT_MQTT_Yield` should have a certain execution time to prevent it from being suspended or preempted for a long time. 13 | ``` 14 | In a multithreaded environment, we recommend you use `IOT_MQTT_StartLoop` and `IOT_MQTT_StopLoop` to start and stop the `IOT_MQTT_Yield` thread on the backend, so that when you need to read MQTT messages, you don't need to proactively call the `IOT_MQTT_Yield` function; instead, the backend thread will read and process them. 15 | For the use cases, please see `samples/mqtt/multi_thread_mqtt_sample`. 16 | 17 | For more information on how to use the APIs of other modules, please see the usage of MQTT APIs. 18 | 19 | ## Multi-Client and Multi-Device Connection 20 | 21 | Starting from v3.2.0, the SDK supports multi-device connection. It encapsulates the status variables and parameters in an object-oriented way, so that, for example, one `MQTT/Shadow Client` instance can correspond to one device. You can provide multiple device identity triplets and create multiple `Client` instances to connect multiple devices at the same time for communication. 22 | For the specific sample code, please see the samples in `samples/multi_client`. You can create multiple threads and create their respective `MQTT/Shadow Client` in each thread, and multiple devices can access the backend service at the same time. 23 | 24 | 25 | -------------------------------------------------------------------------------- /tools/build_scripts/stats_static_lib.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | TARGET=$1 4 | TEMPD=$(mktemp -d -t STATD-XXXX) 5 | TEMPF=$(mktemp -t STATF-XXXX) 6 | 7 | #echo "TARGET = ${TARGET}" 8 | #echo "STAGED = ${STAGED}" 9 | #echo "TEMPD = ${TEMPD}" 10 | 11 | if [ ! -f ${TARGET} ] || [ ! -d ${STAGED} ]; then 12 | echo "Invalid Env" 13 | exit 1 14 | fi 15 | 16 | cp ${TARGET} ${TEMPD} 17 | cd ${TEMPD} 18 | ar xf $(basename ${TARGET}) 19 | rm -f $(basename ${TARGET}) 20 | ${STRIP} *.o > /dev/null 2>&1 21 | 22 | NAME=$1 23 | for obj in $(ls *.o); do 24 | dir=$(find ${STAGED} -name ${obj}|xargs dirname|xargs basename) 25 | printf "%-12s %-32s %s\n" $(basename $1) ${obj} $(du -b ${obj}|awk '{ print $1 }') 26 | done | sort > ${TEMPF} 27 | 28 | MODS=$(cat ${TEMPF}|awk '{ print $1 }'|sort -u) 29 | 30 | TOTAL=$(cat ${TEMPF}|awk '{ sum += $3 } END { print sum }') 31 | # echo "TOTAL = ${TOTAL}" 32 | 33 | SMODS=$( \ 34 | for mod in ${MODS}; do \ 35 | MSIZE=$(grep "^${mod}" ${TEMPF}|awk '{ sum += $3 } END { print sum }'); \ 36 | printf "%-8s %s\n" \ 37 | $(awk -v a=${MSIZE} -v b=${TOTAL} 'BEGIN { printf("%.2f%%\n", a/b*100); }') \ 38 | "${mod}"; \ 39 | done | sort -nr | awk '{ print $2 }' \ 40 | ) 41 | 42 | echo "" 43 | for mod in ${SMODS}; do 44 | MSIZE=$(grep "^${mod}" ${TEMPF}|awk '{ sum += $3 } END { print sum }') 45 | OBJS=$(grep "^${mod}" ${TEMPF}|awk '{ print $2 }') 46 | for obj in ${OBJS}; do 47 | FSIZE=$(grep "\<${obj}\>" ${TEMPF}|awk '{ print $3 }') 48 | printf " %-8s %28s | %-8s %8s %-8s\n" \ 49 | $(awk -v a=${FSIZE} -v b=${MSIZE} 'BEGIN { printf("%.2f%%\n", a/b*100); }') \ 50 | "${obj}" "${mod}" "${FSIZE} /" "${MSIZE}" 51 | done | sort -nr 52 | echo " -----------------------------------------------------------------" 53 | done 54 | 55 | echo "" 56 | for mod in ${MODS}; do 57 | MSIZE=$(grep "^${mod}" ${TEMPF}|awk '{ sum += $3 } END { print sum }') 58 | printf " %-8s %-12s %16s\n" \ 59 | $(awk -v a=${MSIZE} -v b=${TOTAL} 'BEGIN { printf("%.2f%%\n", a/b*100); }') \ 60 | "[ ${mod} ]" "${MSIZE} Bytes" 61 | done | sort -nr 62 | 63 | cd "${OLDPWD}" 64 | rm -rf ${TEMPD} 65 | rm -f ${TEMPF} 66 | -------------------------------------------------------------------------------- /docs/FreeRTOS+lwIP平台移植说明.md: -------------------------------------------------------------------------------- 1 | # 文档说明 2 | 本文档介绍如何将腾讯云物联 C-SDK 移植到**FreeRTOS+lwIP** 平台。 3 | 4 | ## FreeRTOS移植简介 5 | FreeRTOS作为一个微内核系统,主要提供任务创建及调度和任务间通信等OS核心机制,在不同设备平台还需要搭配多个软件组件包括C运行库(如newlib或者ARM CMSIS库)和TCP/IP网络协议栈(如lwIP)才能形成完整的嵌入式运行平台。同时各个设备平台的编译开发环境也各不相同,因此在移植C-SDK的时候,需要根据不同设备的具体情况进行适配。 6 | SDK 在**platform/os/freertos**里面提供了一个基于 **FreeRTOS+lwIP+newlib** 的参考实现,该实现已经在乐鑫ESP8266平台上验证测试过。 7 | 8 | ## 从腾讯云物联 C-SDK 中抽取相关代码 9 | 10 | 因为基于RTOS系统的平台编译方式各不相同,一般无法直接使用SDK 的cmake或者make编译,因此SDK提供了代码抽取功能,可根据需要将相关代码抽取到一个单独的文件夹,文件夹里面的代码层次目录简洁,方便用户拷贝集成到自己的开发环境。 11 | 12 | 首先修改 CMakeLists.txt 中配置为freertos平台,并开启代码抽取功能: 13 | ``` 14 | set(BUILD_TYPE "release") 15 | set(PLATFORM "freertos") 16 | set(EXTRACT_SRC ON) 17 | set(FEATURE_AT_TCP_ENABLED OFF) 18 | ``` 19 | 在Linux环境运行以下命令 20 | ``` 21 | mkdir build 22 | cd build 23 | cmake .. 24 | ``` 25 | 即可在output/qcloud_iot_c_sdk中找到相关代码文件,目录层次如下: 26 | ``` 27 | qcloud_iot_c_sdk 28 | ├── include 29 | │   ├── config.h 30 | │   ├── exports 31 | ├── platform 32 | └── sdk_src 33 | └── internal_inc 34 | ``` 35 | include目录为SDK供用户使用的API及可变参数,其中config.h为根据编译选项生成的编译宏。API具体介绍请参考**C-SDK_API及可变参数说明**。 36 | platform目录为平台相关的代码,可根据设备的具体情况进行修改适配。具体的函数说明请参考文档**C-SDK_Porting跨平台移植概述** 37 | sdk_src为SDK的核心逻辑及协议相关代码,一般不需要修改,其中internal_inc为SDK内部使用的头文件。 38 | 39 | 用户可将qcloud_iot_c_sdk拷贝到其目标平台的编译开发环境,并根据具体情况修改编译选项。 40 | 41 | ## 乐鑫ESP8266 RTOS平台移植示例 42 | 在Linux开发环境基于乐鑫ESP8266 RTOS平台搭建一个工程示例,完整可实际运行例程可参考[基于ESP8266 Launcher开发板的工程](https://github.com/tencentyun/qcloud-iot-c-sdk-porting-examples/tree/master/QCloud_IoT_ESP8266_RTOS) 43 | 44 | ### 1. 获取 ESP8266_RTOS_SDK 并创建工程 45 | 46 | 请参考[ESP8266_RTOS_SDK](https://github.com/espressif/ESP8266_RTOS_SDK) 获取RTOS_SDK 和交叉编译器,并创建一个项目工程 47 | 48 | ### 2. 拷贝SDK代码 49 | 50 | 将上面抽取的qcloud_iot_c_sdk目录拷贝到components/qcloud_iot下面 51 | 52 | 在components/qcloud_iot下面新建一个编译配置文件component.mk,内容如下 53 | ``` 54 | # 55 | # Component Makefile 56 | # 57 | 58 | COMPONENT_ADD_INCLUDEDIRS := \ 59 | qcloud_iot_c_sdk/include \ 60 | qcloud_iot_c_sdk/include/exports \ 61 | qcloud_iot_c_sdk/sdk_src/internal_inc 62 | 63 | COMPONENT_SRCDIRS := \ 64 | qcloud_iot_c_sdk/sdk_src \ 65 | qcloud_iot_c_sdk/platform 66 | 67 | ``` 68 | 69 | 这样就可以将qcloud_iot_c_sdk作为一个组件进行编译了,之后在用户代码里面就可以调用物联 C-SDK的接口进行连接和收发消息。 70 | -------------------------------------------------------------------------------- /external_libs/mbedtls/configs/config-picocoin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Reduced configuration used by Picocoin. 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | /* 22 | * Reduced configuration used by Picocoin. 23 | * 24 | * See README.txt for usage instructions. 25 | * 26 | * Distinguishing features: 27 | * - no SSL/TLS; 28 | * - no X.509; 29 | * - ECDSA/PK and some other chosen crypto bits. 30 | */ 31 | 32 | #ifndef MBEDTLS_CONFIG_H 33 | #define MBEDTLS_CONFIG_H 34 | 35 | /* System support */ 36 | #define MBEDTLS_HAVE_ASM 37 | #define MBEDTLS_HAVE_TIME 38 | 39 | /* mbed TLS feature support */ 40 | #define MBEDTLS_CIPHER_MODE_CBC 41 | #define MBEDTLS_CIPHER_PADDING_PKCS7 42 | #define MBEDTLS_ECP_DP_SECP256K1_ENABLED 43 | #define MBEDTLS_ECDSA_DETERMINISTIC 44 | #define MBEDTLS_PK_PARSE_EC_EXTENDED 45 | #define MBEDTLS_ERROR_STRERROR_DUMMY 46 | #define MBEDTLS_FS_IO 47 | 48 | /* mbed TLS modules */ 49 | #define MBEDTLS_AESNI_C 50 | #define MBEDTLS_AES_C 51 | #define MBEDTLS_ASN1_PARSE_C 52 | #define MBEDTLS_ASN1_WRITE_C 53 | #define MBEDTLS_BASE64_C 54 | #define MBEDTLS_BIGNUM_C 55 | #define MBEDTLS_ECDSA_C 56 | #define MBEDTLS_ECP_C 57 | #define MBEDTLS_ENTROPY_C 58 | #define MBEDTLS_HMAC_DRBG_C 59 | #define MBEDTLS_MD_C 60 | #define MBEDTLS_OID_C 61 | #define MBEDTLS_PADLOCK_C 62 | #define MBEDTLS_PK_C 63 | #define MBEDTLS_PK_PARSE_C 64 | #define MBEDTLS_PK_WRITE_C 65 | #define MBEDTLS_RIPEMD160_C 66 | #define MBEDTLS_SHA1_C 67 | #define MBEDTLS_SHA256_C 68 | 69 | #include "mbedtls/check_config.h" 70 | 71 | #endif /* MBEDTLS_CONFIG_H */ 72 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/wslay_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAY_QUEUE_H 26 | #define WSLAY_QUEUE_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | struct wslay_queue_cell { 35 | void * data; 36 | struct wslay_queue_cell *next; 37 | }; 38 | 39 | struct wslay_queue { 40 | struct wslay_queue_cell *top; 41 | struct wslay_queue_cell *tail; 42 | }; 43 | 44 | struct wslay_queue *wslay_queue_new(void); 45 | void wslay_queue_free(struct wslay_queue *queue); 46 | int wslay_queue_push(struct wslay_queue *queue, void *data); 47 | int wslay_queue_push_front(struct wslay_queue *queue, void *data); 48 | void wslay_queue_pop(struct wslay_queue *queue); 49 | void * wslay_queue_top(struct wslay_queue *queue); 50 | void * wslay_queue_tail(struct wslay_queue *queue); 51 | int wslay_queue_empty(struct wslay_queue *queue); 52 | 53 | #endif /* WSLAY_QUEUE_H */ 54 | -------------------------------------------------------------------------------- /sdk_src/utils/qcloud_iot_device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | #include "qcloud_iot_device.h" 20 | 21 | #include 22 | #include 23 | 24 | #include "qcloud_iot_export.h" 25 | 26 | int iot_device_info_set(DeviceInfo *device_info, const char *product_id, const char *device_name) 27 | { 28 | memset(device_info, 0x0, sizeof(DeviceInfo)); 29 | if ((MAX_SIZE_OF_PRODUCT_ID) < strlen(product_id)) { 30 | Log_e("product name(%s) length:(%lu) exceeding limitation", product_id, strlen(product_id)); 31 | return QCLOUD_ERR_FAILURE; 32 | } 33 | if ((MAX_SIZE_OF_DEVICE_NAME) < strlen(device_name)) { 34 | Log_e("device name(%s) length:(%lu) exceeding limitation", device_name, strlen(device_name)); 35 | return QCLOUD_ERR_FAILURE; 36 | } 37 | 38 | strncpy(device_info->product_id, product_id, MAX_SIZE_OF_PRODUCT_ID); 39 | strncpy(device_info->device_name, device_name, MAX_SIZE_OF_DEVICE_NAME); 40 | 41 | /* construct device-id(@product_id+@device_name) */ 42 | memset(device_info->client_id, 0x0, MAX_SIZE_OF_CLIENT_ID); 43 | int ret = HAL_Snprintf(device_info->client_id, MAX_SIZE_OF_CLIENT_ID, "%s%s", product_id, device_name); 44 | if ((ret < 0) || (ret >= MAX_SIZE_OF_CLIENT_ID)) { 45 | Log_e("set device info failed"); 46 | return QCLOUD_ERR_FAILURE; 47 | } 48 | 49 | Log_i("SDK_Ver: %s, Product_ID: %s, Device_Name: %s", QCLOUD_IOT_DEVICE_SDK_VERSION, device_info->product_id, 50 | device_info->device_name); 51 | return QCLOUD_RET_SUCCESS; 52 | } 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Tencent is pleased to support the open source community by making IoT Hub available. 2 | 3 | Copyright (C) 2016 Tencent. All rights reserved. 4 | 5 | If you have downloaded a copy of the IoT Hub binary from Tencent, please note that the IoT Hub binary is licensed under the MIT License. 6 | 7 | If you have downloaded a copy of the IoT Hub source code from Tencent, please note that IoT Hub source code is licensed under the MIT License, 8 | 9 | except for the third-party components listed below which are subject to different license terms. Your integration of IoT Hub into your own projects may require compliance with the MIT License, 10 | 11 | as well as the other licenses applicable to the third-party components included within IoT Hub. 12 | 13 | A copy of the MIT License is included in this file. 14 | 15 | Open Source Software Licensed under the MIT License: The below software in this distribution may have been modified by Tencent (“Tencent Modifications”). All Tencent Modifications are Copyright (C) 2016 THL A29 Limited. 16 | -------------------------------------------------------------------- 17 | 1. cpp-feather-ini-parser 1.42 18 | Copyright (c) 2014 Turbine1991 19 | 20 | 2. Dirent 1.22 21 | Copyright (c) 2015 Toni Rönkkö 22 | 23 | 24 | Terms of the MIT License: 25 | -------------------------------------------------------------------- 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /docs/en/IoT_Hub/log_upload_Device Log Reporting_EN-US.md: -------------------------------------------------------------------------------- 1 | # Device Log Reporting 2 | ## Overview 3 | The device log reporting feature can report device logs to the cloud over HTTP and display them in the console for you to remotely debug, diagnose, and monitor the device status. Currently, this feature is only supported in the MQTT mode. 4 | After you simply set the compilation macro `FEATURE_LOG_UPLOAD_ENABLED` of the SDK to `y` (which is the default value) and set the reporting level in the console, when you call the `Log_e/w/i/d` API in the code, the logs will be printed out in the terminal and also reported to the cloud for display in the console as shown below. 5 | ![](https://main.qcloudimg.com/raw/09002dd8634e37ef408aa151357bc350.png) 6 | 7 | ## Log Level 8 | For more information on how to set the reporting level, please see the figure below. The greater the level, the more the logs that will be reported. For example, Level 3 (INFO) indicates that logs at the ERROR, WARN, and INFO levels will all be reported, while logs at the DEBUG level will not. This feature is disabled in the console by default, which indicates that devices will report only logs at the ERROR level when an MQTT connection fails. 9 | ![](https://main.qcloudimg.com/raw/78164d487b1d927424fbf7d3ed2f6a43.png) 10 | 11 | ## How to Use 12 | For more code samples, please see the comment descriptions of `mqtt_sample` and `qcloud_iot_export_log.h`. In addition to enabling the compilation macro, you also need to call the `IOT_Log_Init_Uploader` function for initialization. The SDK will periodically report logs in the `IOT_MQTT_Yield` function. Plus, you can also call `IOT_Log_Upload(true)` to forcibly report logs as needed when the program quits unexpectedly. The SDK provides a caching mechanism when it cannot report logs due to HTTP communication errors. It will report logs again after the communication returns to normal. However, you need to provide the relevant callback functions according to the specific device conditions. If the callback functions are not provided, or the provided callback functions are incomplete, the caching mechanism will not work, and the logs will be discarded in case the HTTP communication fails. 13 | 14 | Enable the log reporting feature and make sure that the following option is enabled in the compilation configuration file `CMakeLists.txt`. 15 | ``` 16 | set(FEATURE_LOG_UPLOAD_ENABLED ON) 17 | ``` 18 | -------------------------------------------------------------------------------- /platform/os/nonos/HAL_AT_UART_nonos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "at_client.h" 21 | #include "qcloud_iot_export.h" 22 | #include "qcloud_iot_import.h" 23 | #include "stm32l4xx_hal.h" 24 | #include "utils_ringbuff.h" 25 | 26 | #define HAL_AT_UART_IRQHandler USART1_IRQHandler 27 | extern UART_HandleTypeDef huart1; 28 | static UART_HandleTypeDef *pAtUart = &huart1; 29 | 30 | extern void AT_Uart_Init(void); 31 | extern void at_client_uart_rx_isr_cb(uint8_t *pdata, uint8_t len); 32 | 33 | #include "board.h" 34 | /** 35 | * @brief This function handles AT UART global interrupt,push recv char to ringbuff. 36 | */ 37 | void HAL_AT_UART_IRQHandler(void) 38 | { 39 | uint8_t ch; 40 | if (__HAL_UART_GET_FLAG(pAtUart, UART_FLAG_RXNE) == SET) { 41 | ch = (uint8_t)READ_REG(pAtUart->Instance->RDR) & 0xFF; 42 | /*this callback for at_client*/ 43 | at_client_uart_rx_isr_cb(&ch, 1); 44 | HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); 45 | } 46 | __HAL_UART_CLEAR_PEFLAG(pAtUart); 47 | } 48 | 49 | /** 50 | *pdata: pointer of data for send 51 | *len: len of data to be sent 52 | *return: the len of data send success 53 | * @brief hal api for at data send 54 | */ 55 | int HAL_AT_Uart_Send(void *data, uint32_t size) 56 | { 57 | if (HAL_OK == HAL_UART_Transmit(pAtUart, data, size, 0xFFFF)) { 58 | return size; 59 | } else { 60 | return 0; 61 | } 62 | } 63 | 64 | int HAL_AT_Uart_Init(void) 65 | { 66 | AT_Uart_Init(); 67 | return QCLOUD_RET_SUCCESS; 68 | } 69 | 70 | int HAL_AT_Uart_Deinit(void) 71 | { 72 | return QCLOUD_RET_SUCCESS; 73 | } 74 | -------------------------------------------------------------------------------- /external_libs/mbedtls/configs/config-mini-tls1_1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Minimal configuration for TLS 1.1 (RFC 4346) 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | /* 22 | * Minimal configuration for TLS 1.1 (RFC 4346), implementing only the 23 | * required ciphersuite: MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA 24 | * 25 | * See README.txt for usage instructions. 26 | */ 27 | 28 | #ifndef MBEDTLS_CONFIG_H 29 | #define MBEDTLS_CONFIG_H 30 | 31 | /* System support */ 32 | #define MBEDTLS_HAVE_ASM 33 | #define MBEDTLS_HAVE_TIME 34 | 35 | /* mbed TLS feature support */ 36 | #define MBEDTLS_CIPHER_MODE_CBC 37 | #define MBEDTLS_PKCS1_V15 38 | #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 39 | #define MBEDTLS_SSL_PROTO_TLS1_1 40 | 41 | /* mbed TLS modules */ 42 | #define MBEDTLS_AES_C 43 | #define MBEDTLS_ASN1_PARSE_C 44 | #define MBEDTLS_ASN1_WRITE_C 45 | #define MBEDTLS_BIGNUM_C 46 | #define MBEDTLS_CIPHER_C 47 | #define MBEDTLS_CTR_DRBG_C 48 | #define MBEDTLS_DES_C 49 | #define MBEDTLS_ENTROPY_C 50 | #define MBEDTLS_MD_C 51 | #define MBEDTLS_MD5_C 52 | #define MBEDTLS_NET_C 53 | #define MBEDTLS_OID_C 54 | #define MBEDTLS_PK_C 55 | #define MBEDTLS_PK_PARSE_C 56 | #define MBEDTLS_RSA_C 57 | #define MBEDTLS_SHA1_C 58 | #define MBEDTLS_SHA256_C 59 | #define MBEDTLS_SSL_CLI_C 60 | #define MBEDTLS_SSL_SRV_C 61 | #define MBEDTLS_SSL_TLS_C 62 | #define MBEDTLS_X509_CRT_PARSE_C 63 | #define MBEDTLS_X509_USE_C 64 | 65 | /* For test certificates */ 66 | #define MBEDTLS_BASE64_C 67 | #define MBEDTLS_CERTS_C 68 | #define MBEDTLS_PEM_PARSE_C 69 | 70 | /* For testing with compat.sh */ 71 | #define MBEDTLS_FS_IO 72 | 73 | #include "mbedtls/check_config.h" 74 | 75 | #endif /* MBEDTLS_CONFIG_H */ 76 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/qcloud_iot_http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_HTTP_H_ 17 | #define QCLOUD_IOT_HTTP_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define QCLOUD_HTTP_HEADER_FORMAT \ 24 | "Accept: %s*/*\r\n" \ 25 | "X-TC-Algorithm: %s\r\n" \ 26 | "X-TC-Timestamp: %d\r\n" \ 27 | "X-TC-Nonce: %d\r\n" \ 28 | "X-TC-Signature: %s\r\n" 29 | 30 | #define QCLOUD_SUPPORT_HMACSHA1 "hmacsha1" 31 | 32 | #define QCLOUD_SUPPORT_RSASHA256 "rsa-sha256" 33 | 34 | #define QCLOUD_SHA256_RESULT_LEN (32) 35 | #define QCLOUD_SHA1_RESULT_LEN (20) 36 | 37 | #ifdef AUTH_MODE_CERT 38 | #define QCLOUD_SHAX_RESULT_LEN (QCLOUD_SHA256_RESULT_LEN) 39 | #else 40 | #define QCLOUD_SHAX_RESULT_LEN (QCLOUD_SHA1_RESULT_LEN) 41 | #endif 42 | 43 | typedef struct qcloud_iot_http_header_post_sign { 44 | const char *host; 45 | const char *uri; 46 | char * algorithm; 47 | uint32_t timestamp; 48 | int nonce; 49 | char * request_body_buf; 50 | int request_body_buf_len; 51 | char * secretkey; 52 | void * privatekey; 53 | } QCLOUD_IOT_HTTP_HEADER_POST_SIGN; 54 | 55 | char *qcloud_iot_http_header_create(char *request_body_buf, int request_body_buf_len, const char *host, const char *uri, 56 | char *accept_header, char *secretkey, void *privatekey, long timestamp); 57 | 58 | void qcloud_iot_http_header_destory(char *http_header); 59 | 60 | void *qcloud_iot_http_create_privatekey(char *privatekey_file); 61 | 62 | void qcloud_iot_http_destory_privatekey(char *privatekey_file); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* QCLOUD_IOT_HTTP_H_ */ 69 | -------------------------------------------------------------------------------- /docs/en/IoT_Hub/IoT_Hub C-SDK Getting Started_EN-US.md: -------------------------------------------------------------------------------- 1 | # IoT Hub C-SDK 2 | IoT Hub C-SDK relies on a secure and powerful data channel to enable IoT developers to connect devices to the cloud for two-way communication. 3 | The following are the corresponding documents of the features of the SDK. 4 | 5 | ## Getting Started 6 | The **mqtt_sample_Getting Started.md** document describes how to create devices in the IoT Hub console and quickly try out device connection to IoT Hub over the MQTT protocol for message receiving/sending based on the **mqtt_sample** of the SDK. 7 | 8 | ## Device Shadow 9 | The **shadow_sample_Device Shadow.md** document describes the device shadow feature and demonstrates the data flow and feature of the shadow based on the **shadow_sample** of the SDK. 10 | 11 | ## Firmware Update 12 | The **ota_sample_Firmware Update.md** document describes the firmware update feature and demonstrates the firmware update process and feature based on the **ota_mqtt_sample** of the SDK. 13 | 14 | ## Gateway Feature 15 | The **gateway_sample_Gateway Feature.md** document describes how to apply for a gateway device and bind a subdevice in the IoT Hub console and quickly connect the gateway device to IoT Hub over the MQTT protocol for proxied subdevice connection/disconnection and message receiving/sending based on the **gateway_sample** of the SDK. 16 | 17 | ## Device Interconnection 18 | The **door_aircond_sample_Device Interconnection.md** document describes how to quickly try out device interconnection based on the **aircond_shadow_sample** and **door_mqtt_sample** of the SDK by using the message forwarding and rule engine features of IoT Hub in a smart home scenario. 19 | 20 | ## Dynamic Registration 21 | The **dynreg_dev_sample_Dynamic Registration.md** document describes the device connection authentication and dynamic registration features of IoT Hub. 22 | 23 | ## Broadcast Communication 24 | The **broadcast_sample_Broadcast Communication.md** document describes the broadcast communication feature of IoT Hub. 25 | 26 | ## Sync Communication 27 | The **rrpc_sample_Sync Communication.md** document describes the sync communication feature of IoT Hub. 28 | 29 | ## Device Log Reporting 30 | The **log_upload_Device Log Reporting.md** document describes the device log reporting feature and its usage. 31 | 32 | ## CoAP Communication 33 | The **coap_sample.md** document describes the CoAP communication feature of IoT Hub. 34 | 35 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake_minimum_required(VERSION 2.8) 2 | 3 | # This CMakeLists.txt file intended for: 4 | # - include by master ../CMakeLists.txt 5 | # - embedding wslay library into other projects 6 | 7 | set(PACKAGE_VERSION "1.0.1-DEV") 8 | set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/includes) 9 | set(GEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/includes) 10 | 11 | #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -pedantic-errors -Wno-long-long -DHAVE_ARPA_INET_H") 12 | #include(CheckIncludeFile) 13 | #include(TestBigEndian) 14 | #check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) 15 | #check_include_file("netinet/in.h" HAVE_NETINET_IN_H) 16 | #check_include_file("winsock2.h" HAVE_WINSOCK2_H) 17 | #test_big_endian(WORDS_BIGENDIAN) 18 | 19 | #configure_file(${INCLUDE_DIR}/wslay/wslayver.h.in 20 | # ${GEN_INCLUDE_DIR}/wslay/wslayver.h @ONLY) 21 | #configure_file(config.h.in config.h @ONLY) 22 | 23 | set(HEADERS 24 | wslay_event.h 25 | wslay_frame.h 26 | wslay_net.h 27 | wslay_queue.h 28 | wslay_stack.h 29 | ${INCLUDE_DIR}/wslay/wslay.h) 30 | set(SOURCES 31 | wslay_event.c 32 | wslay_frame.c 33 | wslay_net.c 34 | wslay_queue.c 35 | wslay_stack.c) 36 | 37 | if(${EXTRACT_SRC} STREQUAL "ON") 38 | file(COPY ${SOURCES} DESTINATION ${PROJECT_SOURCE_DIR}/output/qcloud_iot_c_sdk/sdk_src/) 39 | endif() 40 | 41 | set(WSLAY_TARGETS) 42 | if(WSLAY_STATIC) 43 | add_library(wslay STATIC ${SOURCES} ${HEADERS}) 44 | list(APPEND WSLAY_TARGETS wslay) 45 | endif() 46 | if(WSLAY_SHARED) 47 | add_library(wslay_shared SHARED ${SOURCES} ${HEADERS}) 48 | list(APPEND WSLAY_TARGETS wslay_shared) 49 | endif() 50 | 51 | foreach(target ${WSLAY_TARGETS}) 52 | set_property(TARGET ${target} PROPERTY C_STANDARD 99) 53 | target_include_directories(${target} PUBLIC 54 | $ 55 | $ 56 | $) 57 | # target_compile_definitions(${target} PRIVATE "HAVE_CONFIG_H") 58 | endforeach() 59 | 60 | # install 61 | if(WSLAY_CONFIGURE_INSTALL) 62 | include(GNUInstallDirs) 63 | install(TARGETS ${WSLAY_TARGETS} EXPORT wslay 64 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 65 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 66 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 67 | install(DIRECTORY ${INCLUDE_DIR}/ ${GEN_INCLUDE_DIR}/ 68 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 69 | FILES_MATCHING PATTERN "*.h") 70 | endif() 71 | -------------------------------------------------------------------------------- /platform/os/freertos/HAL_AT_UART_freertos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | #include "qcloud_iot_export.h" 16 | #include "qcloud_iot_import.h" 17 | 18 | #ifdef AT_TCP_ENABLED 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "at_client.h" 26 | #include "stm32l4xx_hal.h" 27 | #include "utils_ringbuff.h" 28 | 29 | #define HAL_AT_UART_IRQHandler USART1_IRQHandler 30 | extern UART_HandleTypeDef huart1; 31 | static UART_HandleTypeDef *pAtUart = &huart1; 32 | 33 | extern void AT_Uart_Init(void); 34 | extern void at_client_uart_rx_isr_cb(uint8_t *pdata, uint8_t len); 35 | 36 | #include "board.h" 37 | /** 38 | * @brief This function handles AT UART global interrupt,push recv char to ringbuff. 39 | */ 40 | void HAL_AT_UART_IRQHandler(void) 41 | { 42 | uint8_t ch; 43 | if (__HAL_UART_GET_FLAG(pAtUart, UART_FLAG_RXNE) == SET) { 44 | ch = (uint8_t)READ_REG(pAtUart->Instance->RDR) & 0xFF; 45 | /*this callback for at_client*/ 46 | at_client_uart_rx_isr_cb(&ch, 1); 47 | HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); 48 | } 49 | __HAL_UART_CLEAR_PEFLAG(pAtUart); 50 | } 51 | 52 | /** 53 | *pdata: pointer of data for send 54 | *len: len of data to be sent 55 | *return: the len of data send success 56 | * @brief hal api for at data send 57 | */ 58 | int HAL_AT_Uart_Send(void *data, uint32_t size) 59 | { 60 | if (HAL_OK == HAL_UART_Transmit(pAtUart, data, size, 0xFFFF)) { 61 | return size; 62 | } else { 63 | return 0; 64 | } 65 | } 66 | 67 | int HAL_AT_Uart_Init(void) 68 | { 69 | AT_Uart_Init(); 70 | return QCLOUD_RET_SUCCESS; 71 | } 72 | 73 | int HAL_AT_Uart_Deinit(void) 74 | { 75 | return QCLOUD_RET_SUCCESS; 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /cmake_build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | if [ "$#" -eq "0" ]; then 4 | rm -rf output 5 | rm -rf build 6 | echo "Build all (SDK libs and samples)" 7 | mkdir -p build 8 | cd build 9 | cmake .. 10 | make 11 | exit 12 | elif [ "$#" -eq "1" -a $1 == "samples" ]; then 13 | if [ ! -d "output/release/bin" ]; then 14 | rm -rf output/release/bin 15 | elif [ ! -d "output/debug/bin" ]; then 16 | rm -rf output/debug/bin 17 | else 18 | echo "Output folder not found! Please build SDK first" 19 | exit 20 | fi 21 | rm -rf build 22 | echo "Build samples only" 23 | mkdir -p build 24 | cd build 25 | cmake -DSAMPLE_ONLY=ON .. 26 | make 27 | exit 28 | elif [ "$#" -eq "1" -a $1 == "clean" ]; then 29 | echo "Clean all (SDK lib and samples)" 30 | rm -rf output 31 | rm -rf build 32 | exit 33 | elif [ "$#" -eq "1" -a $1 == "code-check" ]; then 34 | # code-check requires clang-tidy and cpplint 35 | # sudo apt install clang-tidy 36 | # pip install cpplint 37 | echo "run code check" 38 | rm -rf build 39 | mkdir -p build 40 | cd build 41 | cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. 42 | echo "clang-tidy check begin" 43 | clang_extra_arg="-extra-arg=-I/usr/lib/gcc/x86_64-linux-gnu/7/include -extra-arg=-I/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed" 44 | clang_check_rules="-checks=-clang-analyzer-osx*,-clang-analyzer-security.insecureAPI.strcpy,-clang-diagnostic-missing-braces,-clang-diagnostic-varargs" 45 | ../tools/run-clang-tidy ${clang_extra_arg} ${clang_check_rules} >../code-check-clang-tidy.txt 46 | echo "clang-tidy check end" 47 | echo "cpplint check begin" 48 | cd .. 49 | # find ./samples/ ./include/ ./sdk_src/ ./platform/ -name *.c -o -name *.h | xargs clang-format -i 50 | cpplint_rules="--filter=-whitespace/line_length,-readability/casting,-build/include_subdir,-whitespace/braces,-whitespace/comments,-whitespace/blank_line,-whitespace/parens,-whitespace/semicolon,-whitespace/end_of_line,-whitespace/ending_newline,-whitespace/comma,-build/header_guard,-runtime/int,-runtime/printf,-readability/todo,-build/include_order,-build/include_what_you_use" 51 | cpplint_coverage="include/ samples/ platform/ sdk_src/" 52 | cpplint ${cpplint_rules} --recursive ${cpplint_coverage} &>./code-check-cpplint.txt 53 | echo "cpplint check end" 54 | exit 55 | else 56 | echo "Usage: "$0" " 57 | exit 58 | fi 59 | -------------------------------------------------------------------------------- /external_libs/mbedtls/include/mbedtls/platform_time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file platform_time.h 3 | * 4 | * \brief mbed TLS Platform time abstraction 5 | * 6 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_PLATFORM_TIME_H 24 | #define MBEDTLS_PLATFORM_TIME_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /** 37 | * \name SECTION: Module settings 38 | * 39 | * The configuration options you can set for this module are in this section. 40 | * Either change them in config.h or define them on the compiler command line. 41 | * \{ 42 | */ 43 | 44 | /* 45 | * The time_t datatype 46 | */ 47 | #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) 48 | typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t; 49 | #else 50 | /* For time_t */ 51 | #include 52 | typedef time_t mbedtls_time_t; 53 | #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */ 54 | 55 | /* 56 | * The function pointers for time 57 | */ 58 | #if defined(MBEDTLS_PLATFORM_TIME_ALT) 59 | extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time ); 60 | 61 | /** 62 | * \brief Set your own time function pointer 63 | * 64 | * \param time_func the time function implementation 65 | * 66 | * \return 0 67 | */ 68 | int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) ); 69 | #else 70 | #if defined(MBEDTLS_PLATFORM_TIME_MACRO) 71 | #define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO 72 | #else 73 | #define mbedtls_time time 74 | #endif /* MBEDTLS_PLATFORM_TIME_MACRO */ 75 | #endif /* MBEDTLS_PLATFORM_TIME_ALT */ 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* platform_time.h */ 82 | -------------------------------------------------------------------------------- /platform/os/linux/HAL_Log_linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #include "qcloud_iot_export_error.h" 20 | #include "qcloud_iot_export_log.h" 21 | #include "qcloud_iot_import.h" 22 | 23 | #ifdef LOG_UPLOAD 24 | 25 | #define LOG_SAVE_FILE_PATH "upload-fail-save.log" 26 | 27 | size_t HAL_Log_Save(const char *log, size_t wLen) 28 | { 29 | FILE * fp; 30 | size_t len; 31 | 32 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "a+")) == NULL) { 33 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 34 | return 0; 35 | } 36 | 37 | len = fwrite((void *)log, 1, wLen, fp); 38 | Log_d("write %d of %d to log file", len, wLen); 39 | 40 | fclose(fp); 41 | 42 | return len; 43 | } 44 | 45 | size_t HAL_Log_Read(char *buff, size_t rLen) 46 | { 47 | FILE * fp; 48 | size_t len; 49 | 50 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 51 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 52 | return 0; 53 | } 54 | 55 | len = fread((void *)buff, 1, rLen, fp); 56 | Log_d("read %d of %d from log file", len, rLen); 57 | 58 | fclose(fp); 59 | 60 | return len; 61 | } 62 | 63 | int HAL_Log_Del(void) 64 | { 65 | return remove(LOG_SAVE_FILE_PATH); 66 | } 67 | 68 | size_t HAL_Log_Get_Size(void) 69 | { 70 | long length; 71 | FILE *fp; 72 | 73 | /* check if file exists */ 74 | if (access(LOG_SAVE_FILE_PATH, 0)) 75 | return 0; 76 | 77 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 78 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 79 | return 0; 80 | } 81 | 82 | fseek(fp, 0L, SEEK_END); 83 | length = ftell(fp); 84 | fclose(fp); 85 | if (length > 0) 86 | return (size_t)length; 87 | else 88 | return 0; 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /platform/os/windows/HAL_Log_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #include "qcloud_iot_export_error.h" 20 | #include "qcloud_iot_export_log.h" 21 | #include "qcloud_iot_import.h" 22 | 23 | #ifdef LOG_UPLOAD 24 | 25 | #define LOG_SAVE_FILE_PATH "upload-fail-save.log" 26 | 27 | size_t HAL_Log_Save(const char *log, size_t wLen) 28 | { 29 | FILE * fp; 30 | size_t len; 31 | 32 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "a+")) == NULL) { 33 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 34 | return 0; 35 | } 36 | 37 | len = fwrite((void *)log, 1, wLen, fp); 38 | Log_d("write %d of %d to log file", len, wLen); 39 | 40 | fclose(fp); 41 | 42 | return len; 43 | } 44 | 45 | size_t HAL_Log_Read(char *buff, size_t rLen) 46 | { 47 | FILE * fp; 48 | size_t len; 49 | 50 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 51 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 52 | return 0; 53 | } 54 | 55 | len = fread((void *)buff, 1, rLen, fp); 56 | Log_d("read %d of %d from log file", len, rLen); 57 | 58 | fclose(fp); 59 | 60 | return len; 61 | } 62 | 63 | int HAL_Log_Del(void) 64 | { 65 | return remove(LOG_SAVE_FILE_PATH); 66 | } 67 | 68 | size_t HAL_Log_Get_Size(void) 69 | { 70 | long length; 71 | FILE *fp; 72 | 73 | /* check if file exists */ 74 | if (access(LOG_SAVE_FILE_PATH, 0)) 75 | return 0; 76 | 77 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 78 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 79 | return 0; 80 | } 81 | 82 | fseek(fp, 0L, SEEK_END); 83 | length = ftell(fp); 84 | fclose(fp); 85 | if (length > 0) 86 | return (size_t)length; 87 | else 88 | return 0; 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_LIST_H_ 17 | #define QCLOUD_IOT_UTILS_LIST_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | /* 26 | * ListNode iterator direction 27 | */ 28 | typedef enum { LIST_HEAD, LIST_TAIL } ListDirection; 29 | 30 | /* 31 | * define list node 32 | */ 33 | typedef struct ListNode { 34 | struct ListNode *prev; 35 | struct ListNode *next; 36 | void * val; 37 | } ListNode; 38 | 39 | /* 40 | * Double Linked List 41 | */ 42 | typedef struct { 43 | ListNode * head; 44 | ListNode * tail; 45 | unsigned int len; 46 | void (*free)(void *val); 47 | int (*match)(void *a, void *b); 48 | } List; 49 | 50 | /* 51 | * list iterator 52 | */ 53 | typedef struct { 54 | ListNode * next; 55 | ListDirection direction; 56 | } ListIterator; 57 | 58 | /* create node */ 59 | ListNode *list_node_new(void *val); 60 | 61 | /* create list */ 62 | List *list_new(void); 63 | 64 | ListNode *list_rpush(List *self, ListNode *node); 65 | 66 | ListNode *list_lpush(List *self, ListNode *node); 67 | 68 | ListNode *list_find(List *self, void *val); 69 | 70 | ListNode *list_at(List *self, int index); 71 | 72 | ListNode *list_rpop(List *self); 73 | 74 | ListNode *list_lpop(List *self); 75 | 76 | void list_remove(List *self, ListNode *node); 77 | 78 | void list_destroy(List *self); 79 | 80 | /* create iterator */ 81 | ListIterator *list_iterator_new(List *list, ListDirection direction); 82 | 83 | ListIterator *list_iterator_new_from_node(ListNode *node, ListDirection direction); 84 | 85 | ListNode *list_iterator_next(ListIterator *self); 86 | 87 | void list_iterator_destroy(ListIterator *self); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | #endif // QCLOUD_IOT_UTILS_LIST_H_ 93 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/wslay_stack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "wslay_stack.h" 26 | 27 | #include 28 | #include 29 | 30 | struct wslay_stack *wslay_stack_new() 31 | { 32 | struct wslay_stack *stack = (struct wslay_stack *)malloc(sizeof(struct wslay_stack)); 33 | if (!stack) { 34 | return NULL; 35 | } 36 | stack->top = NULL; 37 | return stack; 38 | } 39 | 40 | void wslay_stack_free(struct wslay_stack *stack) 41 | { 42 | struct wslay_stack_cell *p; 43 | if (!stack) { 44 | return; 45 | } 46 | p = stack->top; 47 | while (p) { 48 | struct wslay_stack_cell *next = p->next; 49 | free(p); 50 | p = next; 51 | } 52 | free(stack); 53 | } 54 | 55 | int wslay_stack_push(struct wslay_stack *stack, void *data) 56 | { 57 | struct wslay_stack_cell *new_cell = (struct wslay_stack_cell *)malloc(sizeof(struct wslay_stack_cell)); 58 | if (!new_cell) { 59 | return WSLAY_ERR_NOMEM; 60 | } 61 | new_cell->data = data; 62 | new_cell->next = stack->top; 63 | stack->top = new_cell; 64 | return 0; 65 | } 66 | 67 | void wslay_stack_pop(struct wslay_stack *stack) 68 | { 69 | struct wslay_stack_cell *top = stack->top; 70 | assert(top); 71 | stack->top = top->next; 72 | free(top); 73 | } 74 | 75 | void *wslay_stack_top(struct wslay_stack *stack) 76 | { 77 | assert(stack->top); 78 | return stack->top->data; 79 | } 80 | 81 | int wslay_stack_empty(struct wslay_stack *stack) 82 | { 83 | return stack->top == NULL; 84 | } 85 | -------------------------------------------------------------------------------- /include/exports/qcloud_iot_export_rrpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_EXPORT_RRPC_H_ 17 | #define QCLOUD_IOT_EXPORT_RRPC_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #include "qcloud_iot_import.h" 26 | 27 | #ifdef RRPC_ENABLED 28 | 29 | /* Max len of status in reply msg*/ 30 | #define MAX_RRPC_REPLY_STATUS_LEN 64 31 | 32 | /* Max len of process id*/ 33 | #define MAX_RRPC_PROCESS_ID_LEN 16 34 | 35 | typedef enum _eRRPCReplyCode_ { 36 | eRRPC_SUCCESS = 0, 37 | eRRPC_FAIL = -1, 38 | } eRRPCReplyCode; 39 | 40 | /** 41 | * @brief rrpc msg reply parameter 42 | */ 43 | typedef struct _sRRPCReplyPara { 44 | eRRPCReplyCode code; // reply code. 0:success, ~0:failed 45 | char status_msg[MAX_RRPC_REPLY_STATUS_LEN]; // reply message 46 | char * user_data; // content of user reply 47 | size_t user_data_len; // length of user data 48 | } sRRPCReplyPara; 49 | 50 | /** 51 | * @brief RRPC message callback 52 | */ 53 | typedef void (*OnRRPCMessageCallback)(void *pClient, const char *msg, uint32_t msgLen); 54 | 55 | /** 56 | * @brief Subscribe rrpc topic with message callback 57 | * 58 | * @param pClient pointer of handle to MQTT client 59 | * @param callback rrpc message callback 60 | * @return QCLOUD_RET_SUCCESS when success, otherwise fail 61 | */ 62 | int IOT_RRPC_Init(void *pClient, OnRRPCMessageCallback callback); 63 | 64 | /** 65 | * @brief reply to the rrpc msg 66 | * @param pClient handle to mqtt client 67 | * @param processId process id 68 | * @param pJsonDoc data buffer for reply 69 | * @param sizeOfBuffer length of data buffer 70 | * @param replyPara rrpc reply info 71 | * @return QCLOUD_RET_SUCCESS when success, or err code 72 | * for failure 73 | */ 74 | int IOT_RRPC_Reply(void *pClient, char *pJsonDoc, size_t sizeOfBuffer, sRRPCReplyPara *replyPara); 75 | 76 | #endif 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif // QCLOUD_IOT_EXPORT_RRPC_H_ 83 | -------------------------------------------------------------------------------- /external_libs/wslay/lib/wslay_frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAY_FRAME_H 26 | #define WSLAY_FRAME_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | enum wslay_frame_state { 35 | PREP_HEADER, 36 | SEND_HEADER, 37 | SEND_PAYLOAD, 38 | RECV_HEADER1, 39 | RECV_PAYLOADLEN, 40 | RECV_EXT_PAYLOADLEN, 41 | RECV_MASKKEY, 42 | RECV_PAYLOAD 43 | }; 44 | 45 | struct wslay_frame_opcode_memo { 46 | uint8_t fin; 47 | uint8_t opcode; 48 | uint8_t rsv; 49 | }; 50 | 51 | struct wslay_frame_context { 52 | uint8_t ibuf[512]; 53 | uint8_t * ibufmark; 54 | uint8_t * ibuflimit; 55 | struct wslay_frame_opcode_memo iom; 56 | uint64_t ipayloadlen; 57 | uint64_t ipayloadoff; 58 | uint8_t imask; 59 | uint8_t imaskkey[4]; 60 | enum wslay_frame_state istate; 61 | size_t ireqread; 62 | 63 | uint8_t oheader[14]; 64 | uint8_t * oheadermark; 65 | uint8_t * oheaderlimit; 66 | uint64_t opayloadlen; 67 | uint64_t opayloadoff; 68 | uint8_t omask; 69 | uint8_t omaskkey[4]; 70 | enum wslay_frame_state ostate; 71 | 72 | struct wslay_frame_callbacks callbacks; 73 | void * user_data; 74 | }; 75 | 76 | #endif /* WSLAY_FRAME_H */ 77 | -------------------------------------------------------------------------------- /docs/IoT_Hub/coap_sample_CoAP通讯.md: -------------------------------------------------------------------------------- 1 | # CoAP通讯 2 | IoT Hub支持设备端通过CoAP协议接入,请参考[CoAP 协议说明](https://cloud.tencent.com/document/product/634/14063) 3 | 4 | 请先参考**mqtt_sample_快速入门.md**文档,介绍如何在腾讯云物联网通信IoT Hub控制台创建设备 5 | 6 | ## 编译 SDK 7 | 编译运行示例程序coap_sample,首先修改CMakeLists.txt确保以下选项存在(以密钥认证设备为例) 8 | ``` 9 | set(BUILD_TYPE "release") 10 | set(COMPILE_TOOLS "gcc") 11 | set(PLATFORM "linux") 12 | set(FEATURE_COAP_COMM_ENABLED ON) 13 | set(FEATURE_AUTH_MODE "KEY") 14 | set(FEATURE_AUTH_WITH_NOTLS OFF) 15 | set(FEATURE_DEBUG_DEV_INFO_USED OFF) 16 | ``` 17 | 编译SDK 18 | 19 | ## 填写设备信息 20 | 将上面在腾讯云物联网IoT Hub创建的设备的设备信息(以**密钥认证设备**为例)填写到device_info.json中 21 | ``` 22 | { 23 | "auth_mode":"KEY", 24 | "productId":"S3EUVBRJLB", 25 | "deviceName":"test_device", 26 | "key_deviceinfo":{ 27 | "deviceSecret":"vX6PQqazsGsMyf5SMfs6OA6y" 28 | } 29 | } 30 | ``` 31 | 32 | ## 执行coap_sample 33 | ``` 34 | ./output/release/bin/coap_sample 35 | INF|2019-09-16 23:49:36|device.c|iot_device_info_set(67): SDK_Ver: 3.1.0, Product_ID: S3EUVBRJLB, Device_Name: test_device 36 | INF|2019-09-16 23:49:38|coap_client.c|IOT_COAP_Construct(82): coap connect success 37 | INF|2019-09-16 23:49:38|coap_client_message.c|coap_message_send(402): add coap message id: 9734 into wait list ret: 0 38 | DBG|2019-09-16 23:49:38|coap_client_message.c|_coap_message_handle(295): receive coap piggy ACK message, id 9734 39 | INF|2019-09-16 23:49:38|coap_client_auth.c|_coap_client_auth_callback(43): auth token message success, code_class: 2 code_detail: 5 40 | DBG|2019-09-16 23:49:38|coap_client_auth.c|_coap_client_auth_callback(53): auth_token_len = 10, auth_token = YWAIGGUGUC 41 | DBG|2019-09-16 23:49:38|coap_client_message.c|_coap_message_list_proc(146): remove the message id 9734 from list 42 | INF|2019-09-16 23:49:38|coap_client_message.c|_coap_message_list_proc(85): remove node 43 | INF|2019-09-16 23:49:38|coap_client.c|IOT_COAP_Construct(91): device auth successfully, connid: Xy9W9 44 | INF|2019-09-16 23:49:38|coap_sample.c|main(170): topic name is S3EUVBRJLB/test_device/data 45 | INF|2019-09-16 23:49:38|coap_client_message.c|coap_message_send(402): add coap message id: 9735 into wait list ret: 0 46 | DBG|2019-09-16 23:49:38|coap_sample.c|main(177): client topic has been sent, msg_id: 9735 47 | DBG|2019-09-16 23:49:39|coap_client_message.c|_coap_message_handle(295): receive coap piggy ACK message, id 9735 48 | INF|2019-09-16 23:49:39|coap_sample.c|event_handler(78): message received ACK, msgid: 9735 49 | DBG|2019-09-16 23:49:39|coap_client_message.c|_coap_message_list_proc(146): remove the message id 9735 from list 50 | INF|2019-09-16 23:49:39|coap_client_message.c|_coap_message_list_proc(85): remove node 51 | INF|2019-09-16 23:49:39|coap_client.c|IOT_COAP_Destroy(125): coap release! 52 | ``` -------------------------------------------------------------------------------- /sdk_src/internal_inc/at_uart_hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef __AT_UART_HAL_H__ 17 | #define __AT_UART_HAL_H__ 18 | 19 | /* 20 | * UART data width 21 | */ 22 | typedef enum { 23 | BAUDRATE_2400 = 2400, 24 | BAUDRATE_4800 = 4800, 25 | BAUDRATE_9600 = 9600, 26 | BAUDRATE_19200 = 19200, 27 | BAUDRATE_115200 = 115200, 28 | BAUDRATE_921600 = 921600, 29 | BAUDRATE_DEFAULT = 115200 30 | } hal_uart_baudr_t; 31 | 32 | /* 33 | * UART data width 34 | */ 35 | typedef enum { 36 | DATA_WIDTH_5BIT, 37 | DATA_WIDTH_6BIT, 38 | DATA_WIDTH_7BIT, 39 | DATA_WIDTH_8BIT, 40 | DATA_WIDTH_9BIT 41 | } hal_uart_data_width_t; 42 | 43 | /* 44 | * UART stop bits 45 | */ 46 | typedef enum { STOP_BITS_1, STOP_BITS_2 } hal_uart_stop_bits_t; 47 | 48 | /* 49 | * UART flow control 50 | */ 51 | typedef enum { 52 | FLOW_CONTROL_DISABLED, 53 | FLOW_CONTROL_CTS, 54 | FLOW_CONTROL_RTS, 55 | FLOW_CONTROL_CTS_RTS 56 | } hal_uart_flow_control_t; 57 | 58 | /* 59 | * UART parity 60 | */ 61 | typedef enum { NO_PARITY, ODD_PARITY, EVEN_PARITY } hal_uart_parity_t; 62 | 63 | /* 64 | * UART mode 65 | */ 66 | typedef enum { MODE_TX, MODE_RX, MODE_TX_RX } hal_uart_mode_t; 67 | 68 | /* 69 | * UART state 70 | */ 71 | typedef enum { 72 | eUNUSED = 0, 73 | eOPENED = 1, 74 | eCLOSED = 2, 75 | } hal_uart_state_t; 76 | 77 | /* 78 | * UART configuration 79 | */ 80 | typedef struct { 81 | uint32_t baud_rate; 82 | hal_uart_data_width_t data_width; 83 | hal_uart_parity_t parity; 84 | hal_uart_stop_bits_t stop_bits; 85 | hal_uart_flow_control_t flow_control; 86 | hal_uart_mode_t mode; 87 | } uart_config_t; 88 | 89 | typedef struct { 90 | #ifdef __linux__ 91 | int fd; /* uart fd */ 92 | #else 93 | void *uart_handle; /* uart handle,like stm32 UART_HandleTypeDef */ 94 | #endif 95 | hal_uart_state_t state; /* uart state */ 96 | uart_config_t config; /* uart config */ 97 | } uart_dev_t; 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* __AT_H__ */ 104 | -------------------------------------------------------------------------------- /sdk_src/utils/utils_ringbuff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #include "utils_ringbuff.h" 17 | 18 | #include 19 | #include 20 | 21 | int ring_buff_init(sRingbuff* ring_buff, char* buff, uint32_t size) 22 | { 23 | ring_buff->buffer = buff; 24 | ring_buff->size = size; 25 | ring_buff->readpoint = 0; 26 | ring_buff->writepoint = 0; 27 | memset(ring_buff->buffer, 0, ring_buff->size); 28 | ring_buff->full = false; 29 | 30 | return RINGBUFF_OK; 31 | } 32 | 33 | int ring_buff_flush(sRingbuff* ring_buff) 34 | { 35 | ring_buff->readpoint = 0; 36 | ring_buff->writepoint = 0; 37 | memset(ring_buff->buffer, 0, ring_buff->size); 38 | ring_buff->full = false; 39 | 40 | return RINGBUFF_OK; 41 | } 42 | 43 | int ring_buff_push_data(sRingbuff* ring_buff, uint8_t* pData, int len) 44 | { 45 | int i; 46 | 47 | if (len > ring_buff->size) { 48 | return RINGBUFF_TOO_SHORT; 49 | } 50 | 51 | for (i = 0; i < len; i++) { 52 | if (((ring_buff->writepoint + 1) % ring_buff->size) == ring_buff->readpoint) { 53 | ring_buff->full = true; 54 | return RINGBUFF_FULL; 55 | } else { 56 | if (ring_buff->writepoint < (ring_buff->size - 1)) { 57 | ring_buff->writepoint++; 58 | } else { 59 | ring_buff->writepoint = 0; 60 | } 61 | ring_buff->buffer[ring_buff->writepoint] = pData[i]; 62 | } 63 | } 64 | 65 | return RINGBUFF_OK; 66 | } 67 | 68 | int ring_buff_pop_data(sRingbuff* ring_buff, uint8_t* pData, int len) 69 | { 70 | int i; 71 | 72 | if (len > ring_buff->size) { 73 | return RINGBUFF_TOO_SHORT; 74 | } 75 | 76 | for (i = 0; i < len; i++) { 77 | if (ring_buff->writepoint == ring_buff->readpoint) { 78 | break; 79 | } else { 80 | if (ring_buff->readpoint == (ring_buff->size - 1)) { 81 | ring_buff->readpoint = 0; 82 | } else { 83 | ring_buff->readpoint++; 84 | } 85 | pData[i] = ring_buff->buffer[ring_buff->readpoint]; 86 | } 87 | } 88 | 89 | return i; 90 | } 91 | -------------------------------------------------------------------------------- /external_libs/mbedtls/configs/config-no-entropy.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Minimal configuration of features that do not require an entropy source 3 | * 4 | * Copyright (C) 2016, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | /* 22 | * Minimal configuration of features that do not require an entropy source 23 | * Distinguishing reatures: 24 | * - no entropy module 25 | * - no TLS protocol implementation available due to absence of an entropy 26 | * source 27 | * 28 | * See README.txt for usage instructions. 29 | */ 30 | 31 | #ifndef MBEDTLS_CONFIG_H 32 | #define MBEDTLS_CONFIG_H 33 | 34 | /* System support */ 35 | #define MBEDTLS_HAVE_ASM 36 | #define MBEDTLS_HAVE_TIME 37 | 38 | /* mbed TLS feature support */ 39 | #define MBEDTLS_CIPHER_MODE_CBC 40 | #define MBEDTLS_CIPHER_PADDING_PKCS7 41 | #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES 42 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 43 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED 44 | #define MBEDTLS_ECP_DP_CURVE25519_ENABLED 45 | #define MBEDTLS_ECP_NIST_OPTIM 46 | #define MBEDTLS_ECDSA_DETERMINISTIC 47 | #define MBEDTLS_PK_RSA_ALT_SUPPORT 48 | #define MBEDTLS_PKCS1_V15 49 | #define MBEDTLS_PKCS1_V21 50 | #define MBEDTLS_SELF_TEST 51 | #define MBEDTLS_VERSION_FEATURES 52 | #define MBEDTLS_X509_CHECK_KEY_USAGE 53 | #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 54 | 55 | /* mbed TLS modules */ 56 | #define MBEDTLS_AES_C 57 | #define MBEDTLS_ASN1_PARSE_C 58 | #define MBEDTLS_ASN1_WRITE_C 59 | #define MBEDTLS_BASE64_C 60 | #define MBEDTLS_BIGNUM_C 61 | #define MBEDTLS_CCM_C 62 | #define MBEDTLS_CIPHER_C 63 | #define MBEDTLS_ECDSA_C 64 | #define MBEDTLS_ECP_C 65 | #define MBEDTLS_ERROR_C 66 | #define MBEDTLS_GCM_C 67 | #define MBEDTLS_HMAC_DRBG_C 68 | #define MBEDTLS_MD_C 69 | #define MBEDTLS_OID_C 70 | #define MBEDTLS_PEM_PARSE_C 71 | #define MBEDTLS_PK_C 72 | #define MBEDTLS_PK_PARSE_C 73 | #define MBEDTLS_PK_WRITE_C 74 | #define MBEDTLS_PLATFORM_C 75 | #define MBEDTLS_RSA_C 76 | #define MBEDTLS_SHA256_C 77 | #define MBEDTLS_SHA512_C 78 | #define MBEDTLS_VERSION_C 79 | #define MBEDTLS_X509_USE_C 80 | #define MBEDTLS_X509_CRT_PARSE_C 81 | #define MBEDTLS_X509_CRL_PARSE_C 82 | 83 | #include "check_config.h" 84 | 85 | #endif /* MBEDTLS_CONFIG_H */ 86 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_SHA1_H_ 17 | #define QCLOUD_IOT_UTILS_SHA1_H_ 18 | 19 | #include "qcloud_iot_import.h" 20 | 21 | /** 22 | * \brief SHA-1 context structure 23 | */ 24 | typedef struct { 25 | uint32_t total[2]; /*!< number of bytes processed */ 26 | uint32_t state[5]; /*!< intermediate digest state */ 27 | unsigned char buffer[64]; /*!< data block being processed */ 28 | } iot_sha1_context; 29 | 30 | /** 31 | * \brief Initialize SHA-1 context 32 | * 33 | * \param ctx SHA-1 context to be initialized 34 | */ 35 | void utils_sha1_init(iot_sha1_context *ctx); 36 | 37 | /** 38 | * \brief Clear SHA-1 context 39 | * 40 | * \param ctx SHA-1 context to be cleared 41 | */ 42 | void utils_sha1_free(iot_sha1_context *ctx); 43 | 44 | /** 45 | * \brief Clone (the state of) a SHA-1 context 46 | * 47 | * \param dst The destination context 48 | * \param src The context to be cloned 49 | */ 50 | void utils_sha1_clone(iot_sha1_context *dst, const iot_sha1_context *src); 51 | 52 | /** 53 | * \brief SHA-1 context setup 54 | * 55 | * \param ctx context to be initialized 56 | */ 57 | void utils_sha1_starts(iot_sha1_context *ctx); 58 | 59 | /** 60 | * \brief SHA-1 process buffer 61 | * 62 | * \param ctx SHA-1 context 63 | * \param input buffer holding the data 64 | * \param ilen length of the input data 65 | */ 66 | void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, size_t ilen); 67 | 68 | /** 69 | * \brief SHA-1 final digest 70 | * 71 | * \param ctx SHA-1 context 72 | * \param output SHA-1 checksum result 73 | */ 74 | void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20]); 75 | 76 | /* Internal use */ 77 | void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64]); 78 | 79 | /** 80 | * \brief Output = SHA-1( input buffer ) 81 | * 82 | * \param input buffer holding the data 83 | * \param ilen length of the input data 84 | * \param output SHA-1 checksum result 85 | */ 86 | void utils_sha1(const unsigned char *input, size_t ilen, unsigned char output[20]); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_MD5_H_ 17 | #define QCLOUD_IOT_UTILS_MD5_H_ 18 | 19 | #include "qcloud_iot_import.h" 20 | 21 | typedef struct { 22 | uint32_t total[2]; /*!< number of bytes processed */ 23 | uint32_t state[4]; /*!< intermediate digest state */ 24 | unsigned char buffer[64]; /*!< data block being processed */ 25 | } iot_md5_context; 26 | 27 | /** 28 | * @brief init MD5 context 29 | * 30 | * @param ctx MD5 context 31 | */ 32 | void utils_md5_init(iot_md5_context *ctx); 33 | 34 | /** 35 | * @brief free MD5 context 36 | * 37 | * @param ctx MD5 context 38 | */ 39 | void utils_md5_free(iot_md5_context *ctx); 40 | 41 | /** 42 | * @brief clone MD5 context 43 | * 44 | * @param dst destination MD5 context 45 | * @param src source MD5 context 46 | */ 47 | void utils_md5_clone(iot_md5_context *dst, const iot_md5_context *src); 48 | 49 | /** 50 | * @brief start MD5 calculation 51 | * 52 | * @param ctx MD5 context 53 | */ 54 | void utils_md5_starts(iot_md5_context *ctx); 55 | 56 | /** 57 | * @brief MD5 update 58 | * 59 | * @param ctx MD5 context 60 | * @param input input data 61 | * @param ilen data length 62 | */ 63 | void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, size_t ilen); 64 | 65 | /** 66 | * @brief finish MD5 calculation 67 | * 68 | * @param ctx MD5 context 69 | * @param output MD5 result 70 | */ 71 | void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]); 72 | 73 | /* MD5 internal process */ 74 | void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]); 75 | 76 | /** 77 | * @brief Output = MD5( input buffer ) 78 | * 79 | * @param input data input 80 | * @param ilen data lenght 81 | * @param output MD5 result 82 | */ 83 | void utils_md5(const unsigned char *input, size_t ilen, unsigned char output[16]); 84 | 85 | /** 86 | * @brief Output = MD5( input buffer ) 87 | * 88 | * @param input data input 89 | * @param ilen data lenght 90 | * @param output string MD5 result 91 | */ 92 | void utils_md5_str(const unsigned char *input, size_t ilen, unsigned char *output); 93 | 94 | int8_t utils_hb2hex(uint8_t hb); 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /sdk_src/services/resource/resource_upload.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "resource_upload.h" 21 | #include "utils_url_upload.h" 22 | #include 23 | 24 | #include "qcloud_iot_ca.h" 25 | #include "qcloud_iot_export.h" 26 | #include "qcloud_iot_import.h" 27 | #include "utils_httpc.h" 28 | #include "resource_lib.h" 29 | 30 | #define RESOURCE_HTTP_HEAD_CONTENT_LEN 256 31 | 32 | void *qcloud_resource_upload_http_init(const char *url, char *md5sum, int upload_len) 33 | { 34 | char base64md5[33] = {0}; 35 | char header[RESOURCE_HTTP_HEAD_CONTENT_LEN]; 36 | qcloud_lib_base64encode_md5sum(md5sum, base64md5, sizeof(base64md5)); 37 | 38 | HAL_Snprintf(header, RESOURCE_HTTP_HEAD_CONTENT_LEN, 39 | "Content-MD5:%s\r\n" 40 | "Content-Type: application/x-www-form-urlencoded\r\n" 41 | "Content-Length: %d\r\n", 42 | base64md5, upload_len); 43 | 44 | return qcloud_url_upload_init(url, 0, header); 45 | } 46 | 47 | int32_t qcloud_resource_upload_http_connect(void *handle) 48 | { 49 | return qcloud_url_upload_connect(handle, HTTP_PUT); 50 | } 51 | 52 | int32_t qcloud_resource_upload_http_send_body(void *handle, char *buf, uint32_t buf_len, uint32_t timeout_s) 53 | { 54 | return qcloud_url_upload_body(handle, buf, buf_len, timeout_s); 55 | } 56 | 57 | int32_t qcloud_resource_upload_http_recv(void *handle, char *buf, uint32_t bufLen, uint32_t timeout_s) 58 | { 59 | IOT_FUNC_ENTRY; 60 | int rc; 61 | rc = qcloud_url_upload_recv_response(handle, buf, bufLen, timeout_s * 1000); 62 | 63 | if (QCLOUD_RET_SUCCESS != rc) { 64 | if (rc == QCLOUD_ERR_HTTP_NOT_FOUND) 65 | IOT_FUNC_EXIT_RC(QCLOUD_RESOURCE_ERRCODE_FETCH_NOT_EXIST_E); 66 | 67 | if (rc == QCLOUD_ERR_HTTP_AUTH) 68 | IOT_FUNC_EXIT_RC(QCLOUD_RESOURCE_ERRCODE_FETCH_AUTH_FAIL_E); 69 | 70 | if (rc == QCLOUD_ERR_HTTP_TIMEOUT) 71 | IOT_FUNC_EXIT_RC(QCLOUD_RESOURCE_ERRCODE_FETCH_TIMEOUT_E); 72 | } 73 | 74 | IOT_FUNC_EXIT_RC(rc); 75 | } 76 | 77 | int qcloud_resource_upload_http_deinit(void *handle) 78 | { 79 | return qcloud_url_upload_deinit(handle); 80 | } 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/ota_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef IOT_OTA_LIB_H_ 17 | #define IOT_OTA_LIB_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include "qcloud_iot_export_ota.h" 27 | 28 | void *qcloud_otalib_md5_init(void); 29 | 30 | void qcloud_otalib_md5_update(void *md5, const char *buf, size_t buf_len); 31 | 32 | void qcloud_otalib_md5_finalize(void *md5, char *output_str); 33 | 34 | void qcloud_otalib_md5_deinit(void *md5); 35 | 36 | int qcloud_otalib_get_firmware_type(const char *json, char **type); 37 | 38 | int qcloud_otalib_get_report_version_result(const char *json); 39 | 40 | /** 41 | * @brief Parse firmware info from JSON string 42 | * 43 | * @param json source JSON string 44 | * @param type parsed type 45 | * @param url parsed url 46 | * @param version parsed version 47 | * @param md5 parsed MD5 48 | * @param fileSize parsed file size 49 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 50 | */ 51 | int qcloud_otalib_get_params(const char *json, char **type, char **url, char **version, char *md5, uint32_t *fileSize); 52 | 53 | /** 54 | * @brief Generate firmware info from id and version 55 | * 56 | * @param buf output buffer 57 | * @param bufLen size of buffer 58 | * @param id firmware id 59 | * @param version firmware version 60 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 61 | */ 62 | int qcloud_otalib_gen_info_msg(char *buf, size_t bufLen, uint32_t id, const char *version); 63 | 64 | /** 65 | * @brief Generate firmware report 66 | * 67 | * @param buf output buffer 68 | * @param bufLen size of buffer 69 | * @param id firmware id 70 | * @param version firmware version 71 | * @param progress download progress 72 | * @param reportType report type 73 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 74 | */ 75 | int qcloud_otalib_gen_report_msg(char *buf, size_t bufLen, uint32_t id, const char *version, int progress, 76 | IOT_OTAReportType reportType); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* IOT_OTA_LIB_H_ */ 83 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_httpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_HTTPC_H_ 17 | #define QCLOUD_IOT_UTILS_HTTPC_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #include "network_interface.h" 26 | 27 | #define HTTP_PORT 80 28 | #define HTTPS_PORT 443 29 | 30 | typedef enum { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_HEAD } HttpMethod; 31 | 32 | typedef struct { 33 | int remote_port; 34 | int response_code; 35 | char * header; 36 | char * auth_user; 37 | char * auth_password; 38 | Network network_stack; 39 | } HTTPClient; 40 | 41 | typedef struct { 42 | bool is_more; // if more data to check 43 | bool is_chunked; // if response in chunked data 44 | int retrieve_len; // length of retrieve 45 | int response_content_len; // length of resposne content 46 | int post_buf_len; // post data length 47 | int response_buf_len; // length of response data buffer 48 | char *post_content_type; // type of post content 49 | char *post_buf; // post data buffer 50 | char *response_buf; // response data buffer 51 | } HTTPClientData; 52 | 53 | /** 54 | * @brief do one http request 55 | * 56 | * @param client http client 57 | * @param url server url 58 | * @param port server port 59 | * @param ca_crt_dir ca path 60 | * @param method type of request 61 | * @param client_data http data 62 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 63 | */ 64 | int qcloud_http_client_common(HTTPClient *client, const char *url, int port, const char *ca_crt, HttpMethod method, 65 | HTTPClientData *client_data); 66 | 67 | int qcloud_http_recv_data(HTTPClient *client, uint32_t timeout_ms, HTTPClientData *client_data); 68 | 69 | int qcloud_http_client_connect(HTTPClient *client, const char *url, int port, const char *ca_crt); 70 | 71 | int qcloud_http_send_data(HTTPClient *client, HttpMethod method, uint32_t timeout_ms, HTTPClientData *client_data); 72 | 73 | void qcloud_http_client_close(HTTPClient *client); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | #endif /* QCLOUD_IOT_UTILS_HTTPC_H_ */ 79 | -------------------------------------------------------------------------------- /docs/en/MCU+ universal TCP AT module Porting((FreeRTOS))_EN-US.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | For MCUs that have no network communication capabilities, the "MCU + communication module" combination is often used. Communication modules (including Wi-Fi/2G/4G/NB-IoT) generally provide serial port-based AT instruction protocols for MCUs to communicate over the network. For this scenario, the C-SDK encapsulates the AT-socket network layer, where the core protocol and service layer don't need to be ported. This document describes how to port C-SDK for connection to IoT Hub in the target environment of MCU (FreeRTOS) + universal TCP AT module. 4 | 5 | ## Porting Steps 6 | 7 | ### 1. Download the latest version of the device [C-SDK](https://github.com/tencentyun/qcloud-iot-sdk-embedded-c) 8 | 9 | ### 2. Configure the SDK features and extract the code 10 | - Use the general TCP module to compile and configure the options as follows: 11 | 12 | | Name | Configuration | Description | 13 | | :------------------------------- | ------------- | ------------------------------------------------------------ | 14 | | BUILD_TYPE | debug/release | Set as needed | 15 | | EXTRACT_SRC | ON | Enable code extraction | 16 | | COMPILE_TOOLS | gcc/MSVC | Set as needed and ignore in case of IDE | 17 | | PLATFORM | linux/windows | Set as needed and ignore in case of IDE | 18 | | FEATURE_OTA_COMM_ENABLED | ON/OFF | Set as needed | 19 | | FEATURE_AUTH_MODE | KEY | Key authentication is recommended for resource-constrained devices | 20 | | FEATURE_AUTH_WITH_NOTLS | ON/OFF | Enable TLS as needed | 21 | | FEATURE_AT_TCP_ENABLED | ON | Whether to enable TCP feature in AT module | 22 | | FEATURE_AT_UART_RECV_IRQ | ON | Whether to enable receipt interruption feature in AT module | 23 | | FEATURE_AT_OS_USED | ON | Whether to enable multithreaded feature in AT module | 24 | | FEATURE_AT_DEBUG | OFF | The AT module debugging feature is disabled by default, and it needs to be enabled during debugging | 25 | 26 | - For more information on how to extract the code, please see [C-SDK_Build Compilation Environment and Configuration Option Description](). 27 | 28 | ### 3. Port the HAL 29 | 30 | For more information, please see [C-SDK_Cross-Platform Porting Overview](). 31 | For network HAL APIs, the `AT_Socket` framework provided by the SDK has been selected through the above compilation options. The SDK will call the `at_socket` API of `network_at_tcp.c`. You don't need to port the `at_socket` layer, but you need to implement the AT serial port driver and AT module driver. For the AT module driver, you only need to implement the driver API of the driver structure *`at_device_op_t`* in `at_device` of the AT framework. You can refer to the supported modules in the `at_device` directory. Currently, the SDK provides underlying API implementation for the Wi-Fi module ESP8266, which is widely used in the IoT field, for your reference when you port to other communication modules. 32 | 33 | ### 4. Develop the business logic 34 | 35 | For `IoT_Hub` products, you can refer to the demos in the `Docs/IoT_Hub` directory. 36 | 37 | -------------------------------------------------------------------------------- /external_libs/mbedtls/configs/config-thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Minimal configuration for using TLS as part of Thread 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | 22 | /* 23 | * Minimal configuration for using TLS a part of Thread 24 | * http://threadgroup.org/ 25 | * 26 | * Distinguishing features: 27 | * - no RSA or classic DH, fully based on ECC 28 | * - no X.509 29 | * - support for experimental EC J-PAKE key exchange 30 | * 31 | * See README.txt for usage instructions. 32 | */ 33 | 34 | #ifndef MBEDTLS_CONFIG_H 35 | #define MBEDTLS_CONFIG_H 36 | 37 | /* System support */ 38 | #define MBEDTLS_HAVE_ASM 39 | 40 | /* mbed TLS feature support */ 41 | #define MBEDTLS_AES_ROM_TABLES 42 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 43 | #define MBEDTLS_ECP_NIST_OPTIM 44 | #define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED 45 | #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH 46 | #define MBEDTLS_SSL_PROTO_TLS1_2 47 | #define MBEDTLS_SSL_PROTO_DTLS 48 | #define MBEDTLS_SSL_DTLS_ANTI_REPLAY 49 | #define MBEDTLS_SSL_DTLS_HELLO_VERIFY 50 | #define MBEDTLS_SSL_EXPORT_KEYS 51 | 52 | /* mbed TLS modules */ 53 | #define MBEDTLS_AES_C 54 | #define MBEDTLS_ASN1_PARSE_C 55 | #define MBEDTLS_ASN1_WRITE_C 56 | #define MBEDTLS_BIGNUM_C 57 | #define MBEDTLS_CCM_C 58 | #define MBEDTLS_CIPHER_C 59 | #define MBEDTLS_CTR_DRBG_C 60 | #define MBEDTLS_CMAC_C 61 | #define MBEDTLS_ECJPAKE_C 62 | #define MBEDTLS_ECP_C 63 | #define MBEDTLS_ENTROPY_C 64 | #define MBEDTLS_HMAC_DRBG_C 65 | #define MBEDTLS_MD_C 66 | #define MBEDTLS_OID_C 67 | #define MBEDTLS_PK_C 68 | #define MBEDTLS_PK_PARSE_C 69 | #define MBEDTLS_SHA256_C 70 | #define MBEDTLS_SSL_COOKIE_C 71 | #define MBEDTLS_SSL_CLI_C 72 | #define MBEDTLS_SSL_SRV_C 73 | #define MBEDTLS_SSL_TLS_C 74 | 75 | /* For tests using ssl-opt.sh */ 76 | #define MBEDTLS_NET_C 77 | #define MBEDTLS_TIMING_C 78 | 79 | /* Save RAM at the expense of ROM */ 80 | #define MBEDTLS_AES_ROM_TABLES 81 | 82 | /* Save RAM by adjusting to our exact needs */ 83 | #define MBEDTLS_ECP_MAX_BITS 256 84 | #define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes 85 | 86 | /* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */ 87 | #define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 88 | 89 | #include "mbedtls/check_config.h" 90 | 91 | #endif /* MBEDTLS_CONFIG_H */ 92 | -------------------------------------------------------------------------------- /include/qcloud_iot_export_variables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_EXPORT_VARIABLES_H_ 17 | #define QCLOUD_IOT_EXPORT_VARIABLES_H_ 18 | 19 | /* 20 | * Below variables are dependant on user situation (network status/device memory/application context) 21 | * Adjust the default value to meet your requirement 22 | */ 23 | 24 | /* default MQTT/CoAP timeout value when connect/pub/sub (unit: ms) */ 25 | #define QCLOUD_IOT_MQTT_COMMAND_TIMEOUT (5 * 1000) 26 | 27 | /* default MQTT keep alive interval, in case of celular work, 60 * 1000 recommended (unit: ms) */ 28 | #define QCLOUD_IOT_MQTT_KEEP_ALIVE_INTERNAL (120 * 1000) 29 | 30 | /* default MQTT Tx buffer size, MAX: 16*1024 */ 31 | #define QCLOUD_IOT_MQTT_TX_BUF_LEN (2048) 32 | 33 | /* default MQTT Rx buffer size, MAX: 16*1024 */ 34 | #define QCLOUD_IOT_MQTT_RX_BUF_LEN (2048) 35 | 36 | /* default COAP Tx buffer size, MAX: 1*1024 */ 37 | #define COAP_SENDMSG_MAX_BUFLEN (512) 38 | 39 | /* default COAP Rx buffer size, MAX: 1*1024 */ 40 | #define COAP_RECVMSG_MAX_BUFLEN (512) 41 | 42 | /* MAX MQTT reconnect interval (unit: ms) */ 43 | #define MAX_RECONNECT_WAIT_INTERVAL (60 * 1000) 44 | 45 | /* MAX valid time when connect to MQTT server. 0: always valid */ 46 | /* Use this only if the device has accurate UTC time. Otherwise, set to 0 */ 47 | #define MAX_ACCESS_EXPIRE_TIMEOUT (0) 48 | 49 | /* log print/upload related variables */ 50 | /* MAX size of log buffer for one log item including header and content */ 51 | #define MAX_LOG_MSG_LEN (511) 52 | 53 | #if defined(__linux__) 54 | #undef MAX_LOG_MSG_LEN 55 | #define MAX_LOG_MSG_LEN (1023) 56 | #endif 57 | 58 | #define QCLOUD_IOT_DEFAULT_REGION "china" 59 | 60 | /* 61 | * Log upload related params, which will affect the size of device memory/disk consumption 62 | * the default value can be changed for different user situation 63 | */ 64 | // size of buffer for log upload 65 | #define LOG_UPLOAD_BUFFER_SIZE 5000 66 | 67 | // Max size of one http log upload. Should not larger than 5000 68 | #define MAX_HTTP_LOG_POST_SIZE 3000 69 | 70 | // MAX size for saving log into NVS (files/FLASH) after upload fail 71 | #define MAX_LOG_SAVE_SIZE (3 * LOG_UPLOAD_BUFFER_SIZE) 72 | 73 | // interval of log upload (unit: ms) Decrease this value if LOG_UPLOAD_BUFFER_SIZE is small 74 | #define LOG_UPLOAD_INTERVAL_MS 2000 75 | 76 | #endif /* QCLOUD_IOT_EXPORT_VARIABLES_H_ */ 77 | -------------------------------------------------------------------------------- /platform/os/nonos/HAL_Timer_nonos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "qcloud_iot_import.h" 26 | #include "utils_timer.h" 27 | 28 | #include "stm32l4xx_hal.h" 29 | 30 | static char now_time_str[20] = {0}; 31 | 32 | int HAL_Timer_set_systime_sec(size_t timestamp_sec) 33 | { 34 | #ifndef PLATFORM_HAS_TIME_FUNCS 35 | RTC_DATE_TIME date_time; 36 | date_time.ms = 0; 37 | timestamp_to_date(timestamp_sec, &date_time, 8); 38 | // set RTC Time note hw rtc year base 39 | #endif 40 | return -1; 41 | } 42 | 43 | int HAL_Timer_set_systime_ms(size_t timestamp_ms) 44 | { 45 | #ifndef PLATFORM_HAS_TIME_FUNCS 46 | RTC_DATE_TIME date_time; 47 | date_time.ms = timestamp_ms % 1000; 48 | timestamp_to_date(timestamp_ms / 1000, &date_time, 8); 49 | // set RTC Time note hw rtc year base 50 | #endif 51 | return -1; 52 | } 53 | 54 | uint64_t HAL_GetTimeMs(void) 55 | { 56 | return HAL_GetTick(); 57 | } 58 | 59 | /*Get timestamp*/ 60 | long HAL_Timer_current_sec(void) 61 | { 62 | // return GetTimeStampByAt(NULL); 63 | 64 | return HAL_GetTimeMs() / 1000; 65 | } 66 | 67 | char *HAL_Timer_current(void) 68 | { 69 | long time_sec; 70 | 71 | time_sec = HAL_Timer_current_sec(); 72 | memset(now_time_str, 0, 20); 73 | snprintf(now_time_str, 20, "%ld", time_sec); 74 | 75 | return now_time_str; 76 | } 77 | 78 | bool HAL_Timer_expired(Timer *timer) 79 | { 80 | uint64_t now_ts; 81 | 82 | now_ts = HAL_GetTimeMs(); 83 | 84 | return (now_ts > timer->end_time) ? true : false; 85 | } 86 | 87 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 88 | { 89 | timer->end_time = HAL_GetTimeMs(); 90 | timer->end_time += timeout_ms; 91 | } 92 | 93 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 94 | { 95 | timer->end_time = HAL_GetTimeMs(); 96 | timer->end_time += timeout * 1000; 97 | } 98 | 99 | int HAL_Timer_remain(Timer *timer) 100 | { 101 | return (int)(timer->end_time - HAL_GetTimeMs()); 102 | } 103 | 104 | void HAL_Timer_init(Timer *timer) 105 | { 106 | timer->end_time = 0; 107 | } 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/log_upload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_LOG_UPLOAD_H_ 17 | #define QCLOUD_IOT_LOG_UPLOAD_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "qcloud_iot_export_log.h" 24 | 25 | /** 26 | * @brief init the log upload functions 27 | * 28 | * @param init_params 29 | * @return QCLOUD_RET_SUCCESS when success 30 | */ 31 | int init_log_uploader(LogUploadInitParams *init_params); 32 | 33 | /** 34 | * @brief free log buffer and finish the log upload functions 35 | */ 36 | void fini_log_uploader(void); 37 | 38 | /** 39 | * @brief check if log uploader is init or not 40 | */ 41 | bool is_log_uploader_init(void); 42 | 43 | /** 44 | * @brief append one log item to upload buffer 45 | * 46 | * @param log_content 47 | * @param log_size 48 | * @return 0 when success, -1 when fail 49 | */ 50 | int append_to_upload_buffer(const char *log_content, size_t log_size); 51 | 52 | /** 53 | * @brief clear current upload buffer 54 | * 55 | * @return 56 | */ 57 | void clear_upload_buffer(void); 58 | 59 | /** 60 | * @brief do one upload to server 61 | * 62 | * @param force_upload if true, it will do upload right away, otherwise it will check log_level, buffer left and upload 63 | * interval 64 | * @return QCLOUD_RET_SUCCESS when success or no log to upload or timer is not expired 65 | */ 66 | int do_log_upload(bool force_upload); 67 | 68 | /** 69 | * @brief set the log mqtt client to get system time 70 | * 71 | * @param client 72 | */ 73 | void set_log_mqtt_client(void *client); 74 | 75 | /** 76 | * @brief set if only do log upload when communication error with IoT Hub 77 | * 78 | * @param value if true, only do log upload when communication error with IoT Hub 79 | */ 80 | void set_log_upload_in_comm_err(bool value); 81 | 82 | /** 83 | * @brief get current upload log_level from IoT Hub 84 | * 85 | * @param client 86 | * @param log_level 87 | * @return QCLOUD_RET_SUCCESS when success 88 | */ 89 | int qcloud_get_log_level(void *client, int *log_level); 90 | 91 | /** 92 | * @brief subscribe to upload log_level topic 93 | * 94 | * @param client 95 | * @return QCLOUD_RET_SUCCESS when success 96 | */ 97 | int qcloud_log_topic_subscribe(void *client); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif // QCLOUD_IOT_LOG_UPLOAD_H_ 104 | -------------------------------------------------------------------------------- /sdk_src/utils/utils_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "utils_timer.h" 21 | 22 | static const uint8_t sg_day_num[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 23 | 24 | void timestamp_to_date(size_t timestamp_sec, RTC_DATE_TIME *date_time, int8_t time_zone) 25 | { 26 | date_time->sec = timestamp_sec % 60; 27 | 28 | timestamp_sec /= 60; 29 | date_time->minute = timestamp_sec % 60; 30 | timestamp_sec += (size_t)time_zone * 60; // time_zone add 31 | timestamp_sec /= 60; // to all hour 32 | date_time->hour = timestamp_sec % 24; // calc curr hour 33 | 34 | int day_num = timestamp_sec / 24; // to all day_num 35 | 36 | int leap_num = (day_num + 365) / 1461; // calc leap year num 37 | 38 | if (((day_num + 366) % 1461) == 0) { 39 | date_time->year = (day_num / 366) + 1970 - 0; 40 | date_time->month = 12; 41 | date_time->day = 31; 42 | } else { 43 | day_num -= leap_num; // all year to no leap 44 | date_time->year = (day_num / 365) + 1970 - 0; 45 | day_num %= 365; 46 | day_num += 1; 47 | // curr leap year 48 | if (((date_time->year % 4) == 0) && (day_num == 60)) { 49 | date_time->month = 2; 50 | date_time->day = 29; 51 | } else { 52 | if (((date_time->year % 4) == 0) && (day_num > 60)) { 53 | day_num -= 1; // leap year day_num to not leap year day_num 54 | } 55 | // calc month and day 56 | int month_index; 57 | for (month_index = 0; sg_day_num[month_index] < day_num; month_index++) { 58 | day_num -= sg_day_num[month_index]; 59 | } 60 | date_time->month = (month_index + 1); 61 | date_time->day = day_num; 62 | } 63 | } 64 | 65 | return; 66 | } 67 | 68 | bool expired(Timer *timer) 69 | { 70 | return HAL_Timer_expired(timer); 71 | } 72 | 73 | void countdown_ms(Timer *timer, unsigned int timeout_ms) 74 | { 75 | HAL_Timer_countdown_ms(timer, timeout_ms); 76 | } 77 | 78 | void countdown(Timer *timer, unsigned int timeout) 79 | { 80 | HAL_Timer_countdown(timer, timeout); 81 | } 82 | 83 | int left_ms(Timer *timer) 84 | { 85 | return HAL_Timer_remain(timer); 86 | } 87 | 88 | void InitTimer(Timer *timer) 89 | { 90 | HAL_Timer_init(timer); 91 | } 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | -------------------------------------------------------------------------------- /external_libs/mbedtls/configs/config-ccm-psk-tls1_2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Minimal configuration for TLS 1.2 with PSK and AES-CCM ciphersuites 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | /* 22 | * Minimal configuration for TLS 1.2 with PSK and AES-CCM ciphersuites 23 | * Distinguishing features: 24 | * - no bignum, no PK, no X509 25 | * - fully modern and secure (provided the pre-shared keys have high entropy) 26 | * - very low record overhead with CCM-8 27 | * - optimized for low RAM usage 28 | * 29 | * See README.txt for usage instructions. 30 | */ 31 | #ifndef MBEDTLS_CONFIG_H 32 | #define MBEDTLS_CONFIG_H 33 | 34 | /* System support */ 35 | //#define MBEDTLS_HAVE_TIME /* Optionally used in Hello messages */ 36 | /* Other MBEDTLS_HAVE_XXX flags irrelevant for this configuration */ 37 | 38 | /* mbed TLS feature support */ 39 | #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED 40 | #define MBEDTLS_SSL_PROTO_TLS1_2 41 | 42 | /* mbed TLS modules */ 43 | #define MBEDTLS_AES_C 44 | #define MBEDTLS_CCM_C 45 | #define MBEDTLS_CIPHER_C 46 | #define MBEDTLS_CTR_DRBG_C 47 | #define MBEDTLS_ENTROPY_C 48 | #define MBEDTLS_MD_C 49 | #define MBEDTLS_NET_C 50 | #define MBEDTLS_SHA256_C 51 | #define MBEDTLS_SSL_CLI_C 52 | #define MBEDTLS_SSL_SRV_C 53 | #define MBEDTLS_SSL_TLS_C 54 | 55 | /* Save RAM at the expense of ROM */ 56 | #define MBEDTLS_AES_ROM_TABLES 57 | 58 | /* Save some RAM by adjusting to your exact needs */ 59 | #define MBEDTLS_PSK_MAX_LEN 16 /* 128-bits keys are generally enough */ 60 | 61 | /* 62 | * You should adjust this to the exact number of sources you're using: default 63 | * is the "platform_entropy_poll" source, but you may want to add other ones 64 | * Minimum is 2 for the entropy test suite. 65 | */ 66 | #define MBEDTLS_ENTROPY_MAX_SOURCES 2 67 | 68 | /* 69 | * Use only CCM_8 ciphersuites, and 70 | * save ROM and a few bytes of RAM by specifying our own ciphersuite list 71 | */ 72 | #define MBEDTLS_SSL_CIPHERSUITES \ 73 | MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \ 74 | MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8 75 | 76 | /* 77 | * Save RAM at the expense of interoperability: do this only if you control 78 | * both ends of the connection! (See comments in "mbedtls/ssl.h".) 79 | * The optimal size here depends on the typical size of records. 80 | */ 81 | #define MBEDTLS_SSL_MAX_CONTENT_LEN 512 82 | 83 | #include "mbedtls/check_config.h" 84 | 85 | #endif /* MBEDTLS_CONFIG_H */ 86 | -------------------------------------------------------------------------------- /docs/en/IoT_Hub/coap_sample_CoAP Communication_EN-US.md: -------------------------------------------------------------------------------- 1 | # CoAP Communication 2 | IoT Hub supports device connection over the CoAP protocol. For more information, please see [Device Connection over CoAP](https://cloud.tencent.com/document/product/634/14063). 3 | 4 | Please first refer to the **mqtt_sample_Getting Started.md** document, which describes how to create devices in the IoT Hub console. 5 | 6 | ## Compiling SDK 7 | Compile and run the `coap_sample` demo. First, modify `CMakeLists.txt` and make sure that the following options exist (with a key-authenticated device as example): 8 | ``` 9 | set(BUILD_TYPE "release") 10 | set(COMPILE_TOOLS "gcc") 11 | set(PLATFORM "linux") 12 | set(FEATURE_COAP_COMM_ENABLED ON) 13 | set(FEATURE_AUTH_MODE "KEY") 14 | set(FEATURE_AUTH_WITH_NOTLS OFF) 15 | set(FEATURE_DEBUG_DEV_INFO_USED OFF) 16 | ``` 17 | Compile the SDK 18 | 19 | ## Entering Device Information 20 | Enter the information of the device created above on the IoT Hub platform in `device_info.json` (with a **key-authenticated device** as example). 21 | ``` 22 | { 23 | "auth_mode":"KEY", 24 | "productId":"S3EUVBRJLB", 25 | "deviceName":"test_device", 26 | "key_deviceinfo":{ 27 | "deviceSecret":"vX6PQqazsGsMyf5SMfs6OA6y" 28 | } 29 | } 30 | ``` 31 | 32 | ## Running `coap_sample` 33 | ``` 34 | ./output/release/bin/coap_sample 35 | INF|2019-09-16 23:49:36|device.c|iot_device_info_set(67): SDK_Ver: 3.1.0, Product_ID: S3EUVBRJLB, Device_Name: test_device 36 | INF|2019-09-16 23:49:38|coap_client.c|IOT_COAP_Construct(82): coap connect success 37 | INF|2019-09-16 23:49:38|coap_client_message.c|coap_message_send(402): add coap message id: 9734 into wait list ret: 0 38 | DBG|2019-09-16 23:49:38|coap_client_message.c|_coap_message_handle(295): receive coap piggy ACK message, id 9734 39 | INF|2019-09-16 23:49:38|coap_client_auth.c|_coap_client_auth_callback(43): auth token message success, code_class: 2 code_detail: 5 40 | DBG|2019-09-16 23:49:38|coap_client_auth.c|_coap_client_auth_callback(53): auth_token_len = 10, auth_token = YWAIGGUGUC 41 | DBG|2019-09-16 23:49:38|coap_client_message.c|_coap_message_list_proc(146): remove the message id 9734 from list 42 | INF|2019-09-16 23:49:38|coap_client_message.c|_coap_message_list_proc(85): remove node 43 | INF|2019-09-16 23:49:38|coap_client.c|IOT_COAP_Construct(91): device auth successfully, connid: Xy9W9 44 | INF|2019-09-16 23:49:38|coap_sample.c|main(170): topic name is S3EUVBRJLB/test_device/data 45 | INF|2019-09-16 23:49:38|coap_client_message.c|coap_message_send(402): add coap message id: 9735 into wait list ret: 0 46 | DBG|2019-09-16 23:49:38|coap_sample.c|main(177): client topic has been sent, msg_id: 9735 47 | DBG|2019-09-16 23:49:39|coap_client_message.c|_coap_message_handle(295): receive coap piggy ACK message, id 9735 48 | INF|2019-09-16 23:49:39|coap_sample.c|event_handler(78): message received ACK, msgid: 9735 49 | DBG|2019-09-16 23:49:39|coap_client_message.c|_coap_message_list_proc(146): remove the message id 9735 from list 50 | INF|2019-09-16 23:49:39|coap_client_message.c|_coap_message_list_proc(85): remove node 51 | INF|2019-09-16 23:49:39|coap_client.c|IOT_COAP_Destroy(125): coap release! 52 | ``` -------------------------------------------------------------------------------- /platform/os/rtthread/HAL_Timer_rtthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include 21 | #include 22 | 23 | #include "qcloud_iot_import.h" 24 | #include "utils_timer.h" 25 | 26 | static char now_time_str[20] = {0}; 27 | 28 | int HAL_Timer_set_systime_sec(size_t timestamp_sec) 29 | { 30 | #ifndef PLATFORM_HAS_TIME_FUNCS 31 | RTC_DATE_TIME date_time; 32 | date_time.ms = 0; 33 | timestamp_to_date(timestamp_sec, &date_time, 8); 34 | // set RTC Time note hw rtc year base 35 | return -1; 36 | #endif 37 | } 38 | 39 | int HAL_Timer_set_systime_ms(size_t timestamp_ms) 40 | { 41 | #ifndef PLATFORM_HAS_TIME_FUNCS 42 | RTC_DATE_TIME date_time; 43 | date_time.ms = timestamp_ms % 1000; 44 | timestamp_to_date(timestamp_ms / 1000, &date_time, 8); 45 | // set RTC Time note hw rtc year base 46 | return -1; 47 | #endif 48 | } 49 | 50 | uint32_t HAL_GetTimeMs(void) 51 | { 52 | #if (RT_TICK_PER_SECOND == 1000) 53 | /* #define RT_TICK_PER_SECOND 1000 */ 54 | return (unsigned long)rt_tick_get(); 55 | #else 56 | unsigned long tick = 0; 57 | 58 | tick = rt_tick_get(); 59 | tick = tick * 1000; 60 | return (unsigned long)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND); 61 | #endif 62 | } 63 | 64 | /*Get timestamp*/ 65 | long HAL_Timer_current_sec(void) 66 | { 67 | return HAL_GetTimeMs() / 1000; 68 | } 69 | 70 | char *HAL_Timer_current(void) 71 | { 72 | long time_sec; 73 | 74 | time_sec = HAL_Timer_current_sec(); 75 | memset(now_time_str, 0, 20); 76 | snprintf(now_time_str, 20, "%ld", time_sec); 77 | 78 | return now_time_str; 79 | } 80 | 81 | bool HAL_Timer_expired(Timer *timer) 82 | { 83 | uint32_t now_ts; 84 | 85 | now_ts = HAL_GetTimeMs(); 86 | 87 | return (now_ts > timer->end_time) ? true : false; 88 | } 89 | 90 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 91 | { 92 | timer->end_time = HAL_GetTimeMs(); 93 | timer->end_time += timeout_ms; 94 | } 95 | 96 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 97 | { 98 | timer->end_time = HAL_GetTimeMs(); 99 | timer->end_time += timeout * 1000; 100 | } 101 | 102 | int HAL_Timer_remain(Timer *timer) 103 | { 104 | return (int)(timer->end_time - HAL_GetTimeMs()); 105 | } 106 | 107 | void HAL_Timer_init(Timer *timer) 108 | { 109 | timer->end_time = 0; 110 | } 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /external_libs/mbedtls/include/mbedtls/arc4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file arc4.h 3 | * 4 | * \brief The ARCFOUR stream cipher 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ARC4_H 24 | #define MBEDTLS_ARC4_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #if !defined(MBEDTLS_ARC4_ALT) 35 | // Regular implementation 36 | // 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief ARC4 context structure 44 | */ 45 | typedef struct 46 | { 47 | int x; /*!< permutation index */ 48 | int y; /*!< permutation index */ 49 | unsigned char m[256]; /*!< permutation table */ 50 | } 51 | mbedtls_arc4_context; 52 | 53 | /** 54 | * \brief Initialize ARC4 context 55 | * 56 | * \param ctx ARC4 context to be initialized 57 | */ 58 | void mbedtls_arc4_init( mbedtls_arc4_context *ctx ); 59 | 60 | /** 61 | * \brief Clear ARC4 context 62 | * 63 | * \param ctx ARC4 context to be cleared 64 | */ 65 | void mbedtls_arc4_free( mbedtls_arc4_context *ctx ); 66 | 67 | /** 68 | * \brief ARC4 key schedule 69 | * 70 | * \param ctx ARC4 context to be setup 71 | * \param key the secret key 72 | * \param keylen length of the key, in bytes 73 | */ 74 | void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key, 75 | unsigned int keylen ); 76 | 77 | /** 78 | * \brief ARC4 cipher function 79 | * 80 | * \param ctx ARC4 context 81 | * \param length length of the input data 82 | * \param input buffer holding the input data 83 | * \param output buffer for the output data 84 | * 85 | * \return 0 if successful 86 | */ 87 | int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input, 88 | unsigned char *output ); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #else /* MBEDTLS_ARC4_ALT */ 95 | #include "arc4_alt.h" 96 | #endif /* MBEDTLS_ARC4_ALT */ 97 | 98 | #ifdef __cplusplus 99 | extern "C" { 100 | #endif 101 | 102 | /** 103 | * \brief Checkup routine 104 | * 105 | * \return 0 if successful, or 1 if the test failed 106 | */ 107 | int mbedtls_arc4_self_test( int verbose ); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* arc4.h */ 114 | -------------------------------------------------------------------------------- /platform/os/linux/HAL_Timer_linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include 21 | #include 22 | 23 | #include "qcloud_iot_import.h" 24 | 25 | bool HAL_Timer_expired(Timer *timer) 26 | { 27 | struct timeval now, res; 28 | gettimeofday(&now, NULL); 29 | timersub(&timer->end_time, &now, &res); 30 | return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); 31 | } 32 | 33 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 34 | { 35 | struct timeval now; 36 | gettimeofday(&now, NULL); 37 | struct timeval interval = {timeout_ms / 1000, (timeout_ms % 1000) * 1000}; 38 | timeradd(&now, &interval, &timer->end_time); 39 | } 40 | 41 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 42 | { 43 | struct timeval now; 44 | gettimeofday(&now, NULL); 45 | struct timeval interval = {timeout, 0}; 46 | timeradd(&now, &interval, &timer->end_time); 47 | } 48 | 49 | int HAL_Timer_remain(Timer *timer) 50 | { 51 | struct timeval now, res; 52 | gettimeofday(&now, NULL); 53 | timersub(&timer->end_time, &now, &res); 54 | return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000; 55 | } 56 | 57 | void HAL_Timer_init(Timer *timer) 58 | { 59 | timer->end_time = (struct timeval){0, 0}; 60 | } 61 | 62 | char *HAL_Timer_current(char *time_str) 63 | { 64 | if (time_str == NULL) 65 | return " "; 66 | 67 | struct timeval tv; 68 | gettimeofday(&tv, NULL); 69 | time_t now_time = tv.tv_sec; 70 | 71 | struct tm tm_tmp = *localtime(&now_time); 72 | strftime(time_str, TIME_FORMAT_STR_LEN, "%F %T", &tm_tmp); 73 | 74 | return time_str; 75 | } 76 | 77 | long HAL_Timer_current_sec(void) 78 | { 79 | struct timeval tv; 80 | gettimeofday(&tv, NULL); 81 | 82 | return tv.tv_sec; 83 | } 84 | 85 | int HAL_Timer_set_systime_sec(size_t timestamp_sec) 86 | { 87 | struct timeval stime; 88 | stime.tv_sec = timestamp_sec; 89 | stime.tv_usec = 0; 90 | 91 | if (0 != settimeofday(&stime, NULL)) { 92 | return -1; 93 | } 94 | return 0; 95 | } 96 | 97 | int HAL_Timer_set_systime_ms(size_t timestamp_ms) 98 | { 99 | struct timeval stime; 100 | stime.tv_sec = (timestamp_ms / 1000); 101 | stime.tv_usec = ((timestamp_ms % 1000) * 1000); 102 | 103 | if (0 != settimeofday(&stime, NULL)) { 104 | return -1; 105 | } 106 | return 0; 107 | } 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | -------------------------------------------------------------------------------- /sdk_src/utils/utils_getopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #include "utils_getopt.h" 17 | 18 | #include 19 | #include 20 | 21 | #include "qcloud_iot_import.h" 22 | 23 | static int utils_opterr = 1; /* if error message should be printed */ 24 | static int utils_optind = 1; /* index into parent argv vector */ 25 | static int utils_optopt; /* character checked for validity */ 26 | static int utils_optreset = 1; /* reset getopt */ 27 | 28 | char* utils_optarg; /* argument associated with option */ 29 | 30 | int utils_getopt(int nargc, char* const* nargv, const char* options) 31 | { 32 | #define BADCH (int)'?' 33 | #define BADARG (int)':' 34 | #define EMSG "" 35 | 36 | static char* place = EMSG; /* option letter processing */ 37 | const char* oli; /* option letter list index */ 38 | 39 | if (utils_optreset || !*place) { /* update scanning pointer */ 40 | utils_optreset = 0; 41 | 42 | if (utils_optind >= nargc || *(place = nargv[utils_optind]) != '-') { 43 | utils_optind = 1; 44 | utils_optreset = 1; 45 | place = EMSG; 46 | return (-1); 47 | } 48 | 49 | place++; 50 | } 51 | 52 | /* option letter okay? */ 53 | if ((utils_optopt = (int)*place++) == (int)':' || !(oli = strchr(options, utils_optopt))) { 54 | /* 55 | * if the user didn't specify '-' as an option, 56 | * assume it means -1. 57 | */ 58 | if (utils_optopt == (int)'-') 59 | return (-1); 60 | 61 | if (!*place) 62 | ++utils_optind; 63 | 64 | if (utils_opterr && *options != ':') 65 | HAL_Printf("illegal option - %c\n", utils_optopt); 66 | 67 | return (BADCH); 68 | } 69 | 70 | if (*++oli != ':') { /* don't need argument */ 71 | utils_optarg = NULL; 72 | if (!*place) 73 | ++utils_optind; 74 | } else { 75 | /* need an argument */ 76 | if (*place) { /* no white space */ 77 | utils_optarg = place; 78 | } else if (nargc <= ++utils_optind) { /* no arg */ 79 | place = EMSG; 80 | if (*options == ':') 81 | return (BADARG); 82 | if (utils_opterr) 83 | HAL_Printf("option requires an argument - %c\n", utils_optopt); 84 | return (BADCH); 85 | } else { /* white space */ 86 | utils_optarg = nargv[utils_optind]; 87 | } 88 | 89 | place = EMSG; 90 | ++utils_optind; 91 | } 92 | 93 | /* dump back option letter */ 94 | return (utils_optopt); 95 | } 96 | -------------------------------------------------------------------------------- /tools/build_scripts/rules.mk: -------------------------------------------------------------------------------- 1 | iot_sdk_objects = $(patsubst %.c,%.o, $(IOTSDK_SRC_FILES)) 2 | iot_platform_objects = $(patsubst %.c,%.o, $(IOTPLATFORM_SRC_FILES)) 3 | 4 | .PHONY: config mbedtls wslay clean final-out samples tests 5 | 6 | all: config mbedtls wslay ${COMP_LIB} ${PLATFORM_LIB} final-out samples tests 7 | $(call Compile_Result) 8 | 9 | ${COMP_LIB}: ${iot_sdk_objects} 10 | $(call Brief_Log,"AR") 11 | $(TOP_Q) \ 12 | $(AR) rcs $@ $(iot_sdk_objects) 13 | 14 | $(TOP_Q) \ 15 | rm ${iot_sdk_objects} 16 | 17 | ${PLATFORM_LIB}: ${iot_platform_objects} 18 | $(call Brief_Log,"AR") 19 | $(TOP_Q) \ 20 | $(AR) rcs $@ $(iot_platform_objects) 21 | 22 | $(TOP_Q) \ 23 | rm ${iot_platform_objects} 24 | 25 | config: 26 | $(TOP_Q) \ 27 | mkdir -p ${TEMP_DIR} 28 | $(TOP_Q) echo '' > $(TOP_DIR)/include/config.h 29 | 30 | wslay: 31 | ifneq (,$(filter -DWEBSOCKET_CLIENT,$(CFLAGS))) 32 | $(TOP_Q) \ 33 | make -s -C $(THIRD_PARTY_PATH)/wslay lib -e CC=$(PLATFORM_CC) AR=$(PLATFORM_AR) CFLAGS="$(CFLAGS)" 34 | endif 35 | 36 | mbedtls: 37 | ifeq (,$(filter -DAUTH_WITH_NOTLS,$(CFLAGS))) 38 | $(TOP_Q) \ 39 | make -s -C $(THIRD_PARTY_PATH)/mbedtls lib -e CC=$(PLATFORM_CC) AR=$(PLATFORM_AR) 40 | 41 | $(TOP_Q) \ 42 | cp -RP $(THIRD_PARTY_PATH)/mbedtls/library/libmbedtls.* \ 43 | $(THIRD_PARTY_PATH)/mbedtls/library/libmbedx509.* \ 44 | $(THIRD_PARTY_PATH)/mbedtls/library/libmbedcrypto.* \ 45 | $(TEMP_DIR) 46 | 47 | $(TOP_Q) \ 48 | cd $(TEMP_DIR) && $(AR) x libmbedtls.a \ 49 | && $(AR) x libmbedx509.a \ 50 | && $(AR) x libmbedcrypto.a 51 | endif 52 | 53 | ${iot_sdk_objects}:%.o:%.c 54 | $(call Brief_Log,"CC") 55 | $(TOP_Q) \ 56 | $(PLATFORM_CC) $(CFLAGS) -c $^ -o $@ 57 | 58 | ${iot_platform_objects}:%.o:%.c 59 | $(call Brief_Log,"CC") 60 | $(TOP_Q) \ 61 | $(PLATFORM_CC) $(CFLAGS) -c $^ -o $@ 62 | 63 | final-out : 64 | $(TOP_Q) \ 65 | mkdir -p ${FINAL_DIR} ${DIST_DIR} ${FINAL_DIR}/lib \ 66 | ${FINAL_DIR}/include ${FINAL_DIR}/bin 67 | 68 | $(TOP_Q) \ 69 | mv ${COMP_LIB} ${FINAL_DIR}/lib/ && \ 70 | mv ${PLATFORM_LIB} ${FINAL_DIR}/lib 71 | 72 | $(TOP_Q) \ 73 | cp -rf $(TOP_DIR)/include $(FINAL_DIR)/ 74 | 75 | $(TOP_Q) \ 76 | cp -rf $(TOP_DIR)/certs $(FINAL_DIR)/bin/ 77 | 78 | ifneq (,$(filter -DWEBSOCKET_CLIENT,$(CFLAGS))) 79 | $(TOP_Q) \ 80 | mv $(THIRD_PARTY_PATH)/wslay/lib/libwslay.* ${FINAL_DIR}/lib 81 | endif 82 | 83 | ifeq (,$(filter -DAUTH_WITH_NOTLS,$(CFLAGS))) 84 | $(TOP_Q) \ 85 | mv ${TEMP_DIR}/*.a ${FINAL_DIR}/lib/ 86 | endif 87 | 88 | $(TOP_Q) \ 89 | rm -rf ${TEMP_DIR} 90 | 91 | #include $(SCRIPT_DIR)/rules-tests.mk 92 | 93 | samples: 94 | $(TOP_Q) \ 95 | make -s -C $(SAMPLE_DIR) 96 | 97 | TLSDIR = $(THIRD_PARTY_PATH)/mbedtls 98 | clean: 99 | $(TOP_Q) \ 100 | rm -rf ${TEMP_DIR} 101 | 102 | $(TOP_Q) \ 103 | rm -rf ${DIST_DIR} 104 | 105 | ifeq (,$(filter -DAUTH_WITH_NOTLS,$(CFLAGS))) 106 | ifeq ($(TLSDIR), $(wildcard $(THIRD_PARTY_PATH)/mbedtls)) 107 | $(TOP_Q) \ 108 | make -s -C $(THIRD_PARTY_PATH)/mbedtls clean 109 | endif 110 | endif 111 | 112 | ifneq (,$(filter -DWEBSOCKET_CLIENT,$(CFLAGS))) 113 | $(TOP_Q) \ 114 | make -s -C $(THIRD_PARTY_PATH)/wslay clean 115 | endif 116 | 117 | ifeq (,$(filter -DSDKTESTS_ENABLED,$(CFLAGS))) 118 | $(TOP_Q) \ 119 | rm -rf $(TEST_LIB_DIR) 120 | endif 121 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/utils_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_UTILS_TIMER_H_ 17 | #define QCLOUD_IOT_UTILS_TIMER_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | // Add the platform specific timer includes to define the Timer struct 24 | #include "qcloud_iot_import.h" 25 | 26 | /** 27 | * Define RTC DATE TIME structure 28 | */ 29 | typedef struct { 30 | int year; 31 | int month; 32 | int day; 33 | int hour; 34 | int minute; 35 | int sec; 36 | int ms; 37 | } RTC_DATE_TIME; 38 | 39 | /** 40 | * @brief Check if a timer is expired 41 | * 42 | * Call this function passing in a timer to check if that timer has expired. 43 | * 44 | * @param timer - pointer to the timer to be checked for expiration 45 | * @return bool - true = timer expired, false = timer not expired 46 | */ 47 | bool expired(Timer *timer); 48 | 49 | /** 50 | * @brief Create a timer (milliseconds) 51 | * 52 | * Sets the timer to expire in a specified number of milliseconds. 53 | * 54 | * @param timer - pointer to the timer to be set to expire in milliseconds 55 | * @param timeout_ms - set the timer to expire in this number of milliseconds 56 | */ 57 | void countdown_ms(Timer *timer, unsigned int timeout_ms); 58 | 59 | /** 60 | * @brief Create a timer (seconds) 61 | * 62 | * Sets the timer to expire in a specified number of seconds. 63 | * 64 | * @param timer - pointer to the timer to be set to expire in seconds 65 | * @param timeout - set the timer to expire in this number of seconds 66 | */ 67 | void countdown(Timer *timer, unsigned int timeout); 68 | 69 | /** 70 | * @brief Check the time remaining on a give timer 71 | * 72 | * Checks the input timer and returns the number of milliseconds remaining on the timer. 73 | * 74 | * @param timer - pointer to the timer to be set to checked 75 | * @return int - milliseconds left on the countdown timer 76 | */ 77 | int left_ms(Timer *timer); 78 | 79 | /** 80 | * @brief Initialize a timer 81 | * 82 | * Performs any initialization required to the timer passed in. 83 | * 84 | * @param timer - pointer to the timer to be initialized 85 | */ 86 | void InitTimer(Timer *timer); 87 | 88 | /** 89 | * @brief Time stamp converted to date 90 | * 91 | * Time stamp converted to date 92 | * 93 | * @param timestamp_sec timestamp second 94 | * @param date_time output date_time 95 | * @param time_zone +-time_zone, 8 is china time zone 96 | */ 97 | void timestamp_to_date(size_t timestamp_sec, RTC_DATE_TIME *date_time, int8_t time_zone); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif // QCLOUD_IOT_UTILS_TIMER_H_ 104 | -------------------------------------------------------------------------------- /include/qcloud_iot_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_EXPORT_H_ 17 | #define QCLOUD_IOT_EXPORT_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "config.h" 24 | #include "platform.h" 25 | 26 | /* IoT C-SDK version info */ 27 | #define QCLOUD_IOT_DEVICE_SDK_VERSION "3.3.0" 28 | 29 | /**************** QCloud IoT C-SDK constants begin ************************/ 30 | 31 | /* MAX size of client ID */ 32 | #define MAX_SIZE_OF_CLIENT_ID (80) 33 | 34 | /* MAX size of product ID */ 35 | #define MAX_SIZE_OF_PRODUCT_ID (10) 36 | 37 | /* MAX size of product secret */ 38 | #define MAX_SIZE_OF_PRODUCT_SECRET (32) 39 | 40 | /* MAX size of device name */ 41 | #define MAX_SIZE_OF_DEVICE_NAME (48) 42 | 43 | /* MAX size of device secret */ 44 | #define MAX_SIZE_OF_DEVICE_SECRET (64) 45 | 46 | /* MAX size of device cert file name */ 47 | #define MAX_SIZE_OF_DEVICE_CERT_FILE_NAME (128) 48 | 49 | /* MAX size of device key file name */ 50 | #define MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME (128) 51 | 52 | /* MAX size of region len */ 53 | #define MAX_SIZE_OF_REGION (64) 54 | 55 | /**************** QCloud IoT C-SDK constants end *************************/ 56 | 57 | typedef struct { 58 | char product_id[MAX_SIZE_OF_PRODUCT_ID + 1]; 59 | char device_name[MAX_SIZE_OF_DEVICE_NAME + 1]; 60 | char client_id[MAX_SIZE_OF_CLIENT_ID + 1]; 61 | 62 | #ifdef AUTH_MODE_CERT 63 | char dev_cert_file_name[MAX_SIZE_OF_DEVICE_CERT_FILE_NAME + 1]; 64 | char dev_key_file_name[MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME + 1]; 65 | #else 66 | char device_secret[MAX_SIZE_OF_DEVICE_SECRET + 1]; 67 | #endif 68 | 69 | #ifdef DEV_DYN_REG_ENABLED 70 | char product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1]; 71 | #endif 72 | 73 | char region[MAX_SIZE_OF_REGION]; 74 | } DeviceInfo; 75 | 76 | #ifdef GATEWAY_ENABLED 77 | typedef struct { 78 | DeviceInfo gw_info; 79 | DeviceInfo* sub_dev_info; 80 | unsigned int sub_dev_num; 81 | } GatewayDeviceInfo; 82 | #endif 83 | 84 | #include "qcloud_iot_export_rrpc.h" 85 | #include "qcloud_iot_export_broadcast.h" 86 | #include "qcloud_iot_export_coap.h" 87 | #include "qcloud_iot_export_dynreg.h" 88 | #include "qcloud_iot_export_error.h" 89 | #include "qcloud_iot_export_gateway.h" 90 | #include "qcloud_iot_export_log.h" 91 | #include "qcloud_iot_export_mqtt.h" 92 | #include "qcloud_iot_export_ota.h" 93 | #include "qcloud_iot_export_shadow.h" 94 | #include "qcloud_iot_export_system.h" 95 | #include "qcloud_iot_export_variables.h" 96 | #include "qcloud_iot_export_remote_config.h" 97 | #include "qcloud_iot_export_resource.h" 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* QCLOUD_IOT_EXPORT_H_ */ 104 | -------------------------------------------------------------------------------- /sdk_src/services/resource/resource_lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "resource_lib.h" 21 | 22 | #include 23 | #include 24 | 25 | #include "lite-utils.h" 26 | #include "ota_client.h" 27 | #include "qcloud_iot_export.h" 28 | #include "qcloud_iot_import.h" 29 | #include "utils_md5.h" 30 | #include "utils_base64.h" 31 | 32 | int qcloud_lib_get_json_key_value(char *json_obj, char *json_key, char **value) 33 | { 34 | *value = LITE_json_value_of(json_key, json_obj); 35 | if (NULL == *value) { 36 | Log_e("Not '%s' key in json doc", STRING_PTR_PRINT_SANITY_CHECK(json_key)); 37 | return QCLOUD_RESOURCE_ERRCODE_FAIL_E; 38 | } 39 | 40 | return QCLOUD_RET_SUCCESS; 41 | } 42 | 43 | void qcloud_lib_md5_init(void *ctx_md5) 44 | { 45 | iot_md5_context *ctx = (iot_md5_context *)ctx_md5; 46 | if (NULL == ctx) { 47 | return; 48 | } 49 | 50 | utils_md5_init(ctx); 51 | utils_md5_starts(ctx); 52 | 53 | return; 54 | } 55 | 56 | void qcloud_lib_md5_update(void *md5, const char *buf, size_t buf_len) 57 | { 58 | utils_md5_update(md5, (unsigned char *)buf, buf_len); 59 | } 60 | 61 | void qcloud_lib_md5_finish_tolowercasehex(void *md5, char *output_str) 62 | { 63 | int i; 64 | unsigned char buf_out[16]; 65 | utils_md5_finish(md5, buf_out); 66 | 67 | for (i = 0; i < 16; ++i) { 68 | output_str[i * 2] = utils_hb2hex(buf_out[i] >> 4); 69 | output_str[i * 2 + 1] = utils_hb2hex(buf_out[i]); 70 | } 71 | output_str[32] = '\0'; 72 | } 73 | 74 | int qcloud_lib_base64encode_md5sum(char *md5sumhex, char *outbase64, int outbase64len) 75 | { 76 | char md5[17]; 77 | size_t olen; 78 | 79 | for (int index = 0; index < 16; index++) { 80 | if (md5sumhex[index * 2] < 'a') { 81 | md5[index] = ((md5sumhex[index * 2] - '0') << 4); 82 | } else { 83 | md5[index] = ((10 + (md5sumhex[index * 2] - 'a')) << 4); 84 | } 85 | 86 | if (md5sumhex[index * 2 + 1] < 'a') { 87 | md5[index] += ((md5sumhex[index * 2 + 1] - '0')); 88 | } else { 89 | md5[index] += (10 + (md5sumhex[index * 2 + 1] - 'a')); 90 | } 91 | } 92 | 93 | qcloud_iot_utils_base64encode((unsigned char *)outbase64, outbase64len, &olen, (unsigned char *)md5, 16); 94 | 95 | return (olen > outbase64len) ? QCLOUD_ERR_FAILURE : QCLOUD_RET_SUCCESS; 96 | } 97 | 98 | void qcloud_lib_md5_deinit(void *md5) 99 | { 100 | if (NULL != md5) { 101 | memset(md5, 0, sizeof(iot_md5_context)); 102 | } 103 | } 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | -------------------------------------------------------------------------------- /external_libs/mbedtls/Makefile: -------------------------------------------------------------------------------- 1 | 2 | DESTDIR=/usr/local 3 | PREFIX=mbedtls_ 4 | 5 | .SILENT: 6 | 7 | .PHONY: all lib tests install uninstall clean test check covtest lcov apidoc apidoc_clean 8 | 9 | all: lib 10 | $(MAKE) post_build 11 | 12 | no_test: programs 13 | 14 | programs: lib 15 | $(MAKE) -s -C programs 16 | 17 | lib: 18 | $(MAKE) -C library 19 | 20 | tests: lib 21 | $(MAKE) -C tests 22 | 23 | ifndef WINDOWS 24 | install: no_test 25 | mkdir -p $(DESTDIR)/include/mbedtls 26 | cp -r include/mbedtls $(DESTDIR)/include 27 | 28 | mkdir -p $(DESTDIR)/lib 29 | cp -RP library/libmbedtls.* $(DESTDIR)/lib 30 | cp -RP library/libmbedx509.* $(DESTDIR)/lib 31 | cp -RP library/libmbedcrypto.* $(DESTDIR)/lib 32 | 33 | mkdir -p $(DESTDIR)/bin 34 | for p in programs/*/* ; do \ 35 | if [ -x $$p ] && [ ! -d $$p ] ; \ 36 | then \ 37 | f=$(PREFIX)`basename $$p` ; \ 38 | cp $$p $(DESTDIR)/bin/$$f ; \ 39 | fi \ 40 | done 41 | 42 | uninstall: 43 | rm -rf $(DESTDIR)/include/mbedtls 44 | rm -f $(DESTDIR)/lib/libmbedtls.* 45 | rm -f $(DESTDIR)/lib/libmbedx509.* 46 | rm -f $(DESTDIR)/lib/libmbedcrypto.* 47 | 48 | for p in programs/*/* ; do \ 49 | if [ -x $$p ] && [ ! -d $$p ] ; \ 50 | then \ 51 | f=$(PREFIX)`basename $$p` ; \ 52 | rm -f $(DESTDIR)/bin/$$f ; \ 53 | fi \ 54 | done 55 | endif 56 | 57 | WARNING_BORDER =*******************************************************\n 58 | NULL_ENTROPY_WARN_L1=**** WARNING! MBEDTLS_TEST_NULL_ENTROPY defined! ****\n 59 | NULL_ENTROPY_WARN_L2=**** THIS BUILD HAS NO DEFINED ENTROPY SOURCES ****\n 60 | NULL_ENTROPY_WARN_L3=**** AND IS *NOT* SUITABLE FOR PRODUCTION USE ****\n 61 | 62 | NULL_ENTROPY_WARNING=\n$(WARNING_BORDER)$(NULL_ENTROPY_WARN_L1)$(NULL_ENTROPY_WARN_L2)$(NULL_ENTROPY_WARN_L3)$(WARNING_BORDER) 63 | 64 | # Post build steps 65 | post_build: 66 | ifndef WINDOWS 67 | # If NULL Entropy is configured, display an appropriate warning 68 | -scripts/config.pl get MBEDTLS_TEST_NULL_ENTROPY && ([ $$? -eq 0 ]) && \ 69 | echo '$(NULL_ENTROPY_WARNING)' 70 | endif 71 | 72 | clean: 73 | $(MAKE) -C library clean 74 | ifndef WINDOWS 75 | find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} + 76 | endif 77 | 78 | check: lib tests 79 | $(MAKE) -C tests check 80 | 81 | test: check 82 | 83 | ifndef WINDOWS 84 | # note: for coverage testing, build with: 85 | # make CFLAGS='--coverage -g3 -O0' 86 | covtest: 87 | $(MAKE) check 88 | programs/test/selftest 89 | tests/compat.sh 90 | tests/ssl-opt.sh 91 | 92 | lcov: 93 | rm -rf Coverage 94 | lcov --capture --initial --directory library -o files.info 95 | lcov --capture --directory library -o tests.info 96 | lcov --add-tracefile files.info --add-tracefile tests.info -o all.info 97 | lcov --remove all.info -o final.info '*.h' 98 | gendesc tests/Descriptions.txt -o descriptions 99 | genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info 100 | rm -f files.info tests.info all.info final.info descriptions 101 | 102 | apidoc: 103 | mkdir -p apidoc 104 | doxygen doxygen/mbedtls.doxyfile 105 | 106 | apidoc_clean: 107 | rm -rf apidoc 108 | endif 109 | -------------------------------------------------------------------------------- /sdk_src/internal_inc/qcloud_iot_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2018-2020 Tencent. All rights reserved. 4 | 5 | * Licensed under the MIT License (the "License"); you may not use this file except in 6 | * compliance with the License. You may obtain a copy of the License at 7 | * http://opensource.org/licenses/MIT 8 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 10 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 11 | * either express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | */ 15 | 16 | #ifndef QCLOUD_IOT_COMMON_H_ 17 | #define QCLOUD_IOT_COMMON_H_ 18 | 19 | /* IoT C-SDK APPID */ 20 | #define QCLOUD_IOT_DEVICE_SDK_APPID "21010406" 21 | #define QCLOUD_IOT_DEVICE_SDK_APPID_LEN (sizeof(QCLOUD_IOT_DEVICE_SDK_APPID) - 1) 22 | 23 | #define QCLOUD_IOT_MQTT_DOMAIN_WITH_PREFIX 1 24 | 25 | /* MQTT server domain */ 26 | #define QCLOUD_IOT_MQTT_COAP_DIRECT_DOMAIN "iotcloud.tencentdevices.com" 27 | #define QCLOUD_IOT_MQTT_COAP_US_EAST_DOMAIN "us-east.iotcloud.tencentdevices.com" 28 | #define QCLOUD_IOT_MQTT_COAP_EUROPE_DOMAIN "europe.iothub.tencentdevices.com" 29 | #define QCLOUD_IOT_MQTT_COAP_AP_BANGKOK_DOMAIN "ap-bangkok.iothub.tencentdevices.com" 30 | 31 | #define MQTT_SERVER_PORT_TLS 8883 32 | #define MQTT_SERVER_PORT_NOTLS 1883 33 | 34 | #define COAP_SERVER_PORT 5684 35 | 36 | /* WEBSOCKET MQTT server domain */ 37 | #define QCLOUD_IOT_WEBSOCKET_MQTT_DIRECT_DOMAIN "ap-guangzhou.iothub.tencentdevices.com" 38 | #define QCLOUD_IOT_WEBSOCKET_MQTT_US_EAST_DOMAIN "us-east.iothub.tencentdevices.com" 39 | #define QCLOUD_IOT_WEBSOCKET_MQTT_EUROPE_DOMAIN "europe.iothub.tencentdevices.com" 40 | #define QCLOUD_IOT_WEBSOCKET_MQTT_AP_BANGKOK_DOMAIN "ap-bangkok.iothub.tencentdevices.com" 41 | 42 | #define QCLOUD_IOT_WEBSOCKET_MQTT_SERVER_PORT_TLS 443 43 | #define QCLOUD_IOT_WEBSOCKET_MQTT_SERVER_PORT_NOTLS 80 44 | 45 | /* server domain for dynamic registering device */ 46 | #define DYNREG_LOG_SERVER_URL "ap-guangzhou.gateway.tencentdevices.com" 47 | #define DYNREG_LOG_SERVER_US_EAST_URL "us-east.gateway.tencentdevices.com" 48 | #define DYNREG_LOG_SERVER_EUROPE_URL "europe.gateway.tencentdevices.com" 49 | #define DYNREG_LOG_SERVER_AP_BANGKOK_URL "ap-bangkok.gateway.tencentdevices.com" 50 | 51 | #define DYN_REG_SERVER_URL_PATH "/device/register" 52 | #define DYN_REG_SERVER_PORT 80 53 | #define DYN_REG_SERVER_PORT_TLS 443 54 | 55 | #define LOG_UPLOAD_SERVER_POSTFIX "gateway.tencentdevices.com" 56 | #define UPLOAD_LOG_URI_PATH "/device/reportlog" 57 | #define LOG_UPLOAD_SERVER_PORT 80 58 | 59 | #define REMOTE_LOGIN_WEBSOCKET_SSH_URL "ap-guangzhou.gateway.tencentdevices.com/ssh/device" 60 | #define REMOTE_LOGIN_WEBSOCKET_SSH_US_EAST_URL "us-east.gateway.tencentdevices.com/ssh/device" 61 | #define REMOTE_LOGIN_WEBSOCKET_SSH_EUROPE_URL "europe.gateway.tencentdevices.com/ssh/device" 62 | #define REMOTE_LOGIN_WEBSOCKET_SSH_AP_BANGKOK_URL "ap-bangkok.gateway.tencentdevices.com/ssh/device" 63 | 64 | #define LOCAL_SSH_PORT 22 65 | #define LOCAL_SSH_IP "127.0.0.1" 66 | 67 | /* Max size of a host name */ 68 | #define HOST_STR_LENGTH 64 69 | 70 | /* Max size of base64 encoded PSK = 64, after decode: 64/4*3 = 48*/ 71 | #define DECODE_PSK_LENGTH 48 72 | 73 | #endif /* QCLOUD_IOT_COMMON_H_ */ 74 | -------------------------------------------------------------------------------- /external_libs/mbedtls/include/mbedtls/base64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file base64.h 3 | * 4 | * \brief RFC 1521 base64 encoding/decoding 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_BASE64_H 24 | #define MBEDTLS_BASE64_H 25 | 26 | #include 27 | 28 | #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ 29 | #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /** 36 | * \brief Encode a buffer into base64 format 37 | * 38 | * \param dst destination buffer 39 | * \param dlen size of the destination buffer 40 | * \param olen number of bytes written 41 | * \param src source buffer 42 | * \param slen amount of data to be encoded 43 | * 44 | * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL. 45 | * *olen is always updated to reflect the amount 46 | * of data that has (or would have) been written. 47 | * If that length cannot be represented, then no data is 48 | * written to the buffer and *olen is set to the maximum 49 | * length representable as a size_t. 50 | * 51 | * \note Call this function with dlen = 0 to obtain the 52 | * required buffer size in *olen 53 | */ 54 | int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, 55 | const unsigned char *src, size_t slen ); 56 | 57 | /** 58 | * \brief Decode a base64-formatted buffer 59 | * 60 | * \param dst destination buffer (can be NULL for checking size) 61 | * \param dlen size of the destination buffer 62 | * \param olen number of bytes written 63 | * \param src source buffer 64 | * \param slen amount of data to be decoded 65 | * 66 | * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or 67 | * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is 68 | * not correct. *olen is always updated to reflect the amount 69 | * of data that has (or would have) been written. 70 | * 71 | * \note Call this function with *dst = NULL or dlen = 0 to obtain 72 | * the required buffer size in *olen 73 | */ 74 | int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, 75 | const unsigned char *src, size_t slen ); 76 | 77 | /** 78 | * \brief Checkup routine 79 | * 80 | * \return 0 if successful, or 1 if the test failed 81 | */ 82 | int mbedtls_base64_self_test( int verbose ); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* base64.h */ 89 | --------------------------------------------------------------------------------