├── README.md ├── SConscript ├── docs ├── C-SDK_API及可变参数说明.md ├── C-SDK_Build编译环境及配置选项说明.md ├── C-SDK_Porting跨平台移植概述.md ├── IoT_Explorer开发平台快速入门.md ├── 二进制数据上报.md ├── 数据模板开发 │ ├── 数据模板代码生成.md │ ├── 数据模板协议.md │ └── 数据模板应用开发.md ├── 网关设备快速入门.md └── 设备固件升级.md ├── ports ├── rtthread │ ├── HAL_Device_rtthread.c │ ├── HAL_OS_rtthread.c │ ├── HAL_TCP_rtthread.c │ ├── HAL_Timer_rtthread.c │ └── HAL_UDP_rtthread.c └── ssl │ ├── HAL_DTLS_mbedtls.c │ ├── HAL_TLS_mbedtls.c │ └── tc_tls_config.h ├── qcloud-iot-explorer-sdk-embedded-c ├── .clang-format ├── CMakeLists.txt ├── CMakeSettings.json ├── LICENSE ├── Makefile ├── README.md ├── certs │ └── README.md ├── cmake_build.sh ├── device_info.json ├── docs │ ├── C-SDK_API及可变参数说明.md │ ├── C-SDK_Build编译环境及配置选项说明.md │ ├── C-SDK_Porting跨平台移植概述.md │ ├── Device_Auth设备接入认证.md │ ├── Device_Type设备类型说明.md │ ├── FreeRTOS+lwIP平台移植说明.md │ ├── IoT_Explorer开发平台快速入门.md │ ├── MCU+腾讯云定制AT模组.md │ ├── MCU+通用TCP_AT模组移植(FreeRTOS).md │ ├── MCU+通用TCP_AT模组移植(nonOS).md │ ├── 二进制数据上报.md │ ├── 数据模板开发 │ │ ├── 数据模板代码生成.md │ │ ├── 数据模板协议.md │ │ └── 数据模板应用开发.md │ ├── 网关设备快速入门.md │ └── 设备固件升级.md ├── external_libs │ └── mbedtls │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── configs │ │ ├── README.txt │ │ ├── config-ccm-psk-tls1_2.h │ │ ├── config-mini-tls1_1.h │ │ ├── config-no-entropy.h │ │ ├── config-picocoin.h │ │ ├── config-suite-b.h │ │ └── config-thread.h │ │ ├── include │ │ └── mbedtls │ │ │ ├── aes.h │ │ │ ├── aesni.h │ │ │ ├── arc4.h │ │ │ ├── asn1.h │ │ │ ├── asn1write.h │ │ │ ├── base64.h │ │ │ ├── bignum.h │ │ │ ├── blowfish.h │ │ │ ├── bn_mul.h │ │ │ ├── camellia.h │ │ │ ├── ccm.h │ │ │ ├── certs.h │ │ │ ├── check_config.h │ │ │ ├── cipher.h │ │ │ ├── cipher_internal.h │ │ │ ├── cmac.h │ │ │ ├── compat-1.3.h │ │ │ ├── config.h │ │ │ ├── ctr_drbg.h │ │ │ ├── debug.h │ │ │ ├── des.h │ │ │ ├── dhm.h │ │ │ ├── ecdh.h │ │ │ ├── ecdsa.h │ │ │ ├── ecjpake.h │ │ │ ├── ecp.h │ │ │ ├── entropy.h │ │ │ ├── entropy_poll.h │ │ │ ├── error.h │ │ │ ├── gcm.h │ │ │ ├── havege.h │ │ │ ├── hmac_drbg.h │ │ │ ├── md.h │ │ │ ├── md2.h │ │ │ ├── md4.h │ │ │ ├── md5.h │ │ │ ├── md_internal.h │ │ │ ├── memory_buffer_alloc.h │ │ │ ├── net.h │ │ │ ├── net_sockets.h │ │ │ ├── oid.h │ │ │ ├── padlock.h │ │ │ ├── pem.h │ │ │ ├── pk.h │ │ │ ├── pk_internal.h │ │ │ ├── pkcs11.h │ │ │ ├── pkcs12.h │ │ │ ├── pkcs5.h │ │ │ ├── platform.h │ │ │ ├── platform_time.h │ │ │ ├── ripemd160.h │ │ │ ├── rsa.h │ │ │ ├── sha1.h │ │ │ ├── sha256.h │ │ │ ├── sha512.h │ │ │ ├── ssl.h │ │ │ ├── ssl_cache.h │ │ │ ├── ssl_ciphersuites.h │ │ │ ├── ssl_cookie.h │ │ │ ├── ssl_internal.h │ │ │ ├── ssl_ticket.h │ │ │ ├── threading.h │ │ │ ├── timing.h │ │ │ ├── version.h │ │ │ ├── x509.h │ │ │ ├── x509_crl.h │ │ │ ├── x509_crt.h │ │ │ ├── x509_csr.h │ │ │ └── xtea.h │ │ └── library │ │ ├── Makefile │ │ ├── aes.c │ │ ├── aesni.c │ │ ├── arc4.c │ │ ├── asn1parse.c │ │ ├── asn1write.c │ │ ├── base64.c │ │ ├── bignum.c │ │ ├── blowfish.c │ │ ├── camellia.c │ │ ├── ccm.c │ │ ├── certs.c │ │ ├── cipher.c │ │ ├── cipher_wrap.c │ │ ├── cmac.c │ │ ├── ctr_drbg.c │ │ ├── debug.c │ │ ├── des.c │ │ ├── dhm.c │ │ ├── ecdh.c │ │ ├── ecdsa.c │ │ ├── ecjpake.c │ │ ├── ecp.c │ │ ├── ecp_curves.c │ │ ├── entropy.c │ │ ├── entropy_poll.c │ │ ├── error.c │ │ ├── gcm.c │ │ ├── havege.c │ │ ├── hmac_drbg.c │ │ ├── md.c │ │ ├── md2.c │ │ ├── md4.c │ │ ├── md5.c │ │ ├── md_wrap.c │ │ ├── memory_buffer_alloc.c │ │ ├── net_sockets.c │ │ ├── oid.c │ │ ├── padlock.c │ │ ├── pem.c │ │ ├── pk.c │ │ ├── pk_wrap.c │ │ ├── pkcs11.c │ │ ├── pkcs12.c │ │ ├── pkcs5.c │ │ ├── pkparse.c │ │ ├── pkwrite.c │ │ ├── platform.c │ │ ├── ripemd160.c │ │ ├── rsa.c │ │ ├── sha1.c │ │ ├── sha256.c │ │ ├── sha512.c │ │ ├── ssl_cache.c │ │ ├── ssl_ciphersuites.c │ │ ├── ssl_cli.c │ │ ├── ssl_cookie.c │ │ ├── ssl_srv.c │ │ ├── ssl_ticket.c │ │ ├── ssl_tls.c │ │ ├── threading.c │ │ ├── timing.c │ │ ├── version.c │ │ ├── version_features.c │ │ ├── x509.c │ │ ├── x509_create.c │ │ ├── x509_crl.c │ │ ├── x509_crt.c │ │ ├── x509_csr.c │ │ ├── x509write_crt.c │ │ ├── x509write_csr.c │ │ └── xtea.c ├── include │ ├── config.h │ ├── exports │ │ ├── qcloud_iot_export_data_template.h │ │ ├── qcloud_iot_export_dynreg.h │ │ ├── qcloud_iot_export_error.h │ │ ├── qcloud_iot_export_gateway.h │ │ ├── qcloud_iot_export_log.h │ │ ├── qcloud_iot_export_method.h │ │ ├── qcloud_iot_export_mqtt.h │ │ ├── qcloud_iot_export_ota.h │ │ └── qcloud_iot_export_system.h │ ├── lite-list.h │ ├── lite-utils.h │ ├── platform.h │ ├── qcloud_iot_export.h │ ├── qcloud_iot_export_variables.h │ ├── qcloud_iot_import.h │ └── utils_getopt.h ├── make.settings ├── platform │ ├── CMakeLists.txt │ ├── at_device │ │ └── esp8266 │ │ │ ├── at_device_esp8266.c │ │ │ └── at_device_esp8266.h │ ├── os │ │ ├── freertos │ │ │ ├── HAL_AT_UART_freertos.c │ │ │ ├── HAL_Device_freertos.c │ │ │ ├── HAL_OS_freertos.c │ │ │ ├── HAL_TCP_lwip.c │ │ │ ├── HAL_Timer_freertos.c │ │ │ └── HAL_UDP_lwip.c │ │ ├── linux │ │ │ ├── HAL_AT_UART_linux.c │ │ │ ├── HAL_Device_linux.c │ │ │ ├── HAL_Log_linux.c │ │ │ ├── HAL_OS_linux.c │ │ │ ├── HAL_TCP_linux.c │ │ │ ├── HAL_Timer_linux.c │ │ │ └── HAL_UDP_linux.c │ │ ├── nonos │ │ │ ├── HAL_AT_UART_nonos.c │ │ │ ├── HAL_Device_nonos.c │ │ │ ├── HAL_OS_nonos.c │ │ │ └── HAL_Timer_nonos.c │ │ ├── rtthread │ │ │ ├── HAL_Device_rtthread.c │ │ │ ├── HAL_OS_rtthread.c │ │ │ ├── HAL_TCP_rtthread.c │ │ │ ├── HAL_TLS_mbedtls_rtthread.c │ │ │ ├── HAL_Timer_rtthread.c │ │ │ └── tc_tls_config.h │ │ └── windows │ │ │ ├── HAL_AT_UART_win.c │ │ │ ├── HAL_Device_win.c │ │ │ ├── HAL_Log_win.c │ │ │ ├── HAL_OS_win.c │ │ │ ├── HAL_TCP_win.c │ │ │ ├── HAL_Timer_win.c │ │ │ └── HAL_UDP_win.c │ └── tls │ │ └── mbedtls │ │ ├── HAL_DTLS_mbedtls.c │ │ └── HAL_TLS_mbedtls.c ├── samples │ ├── CMakeLists.txt │ ├── Makefile │ ├── data_template │ │ ├── action_config.c │ │ ├── data_config.c │ │ ├── data_template_sample.c │ │ └── events_config.c │ ├── dynreg_dev │ │ └── dynreg_dev_sample.c │ ├── gateway │ │ ├── gateway_sample.c │ │ └── sub_dev001.c │ ├── mqtt │ │ └── mqtt_sample.c │ ├── ota │ │ └── ota_mqtt_sample.c │ ├── raw_data │ │ └── raw_data_sample.c │ └── scenarized │ │ └── light_data_template_sample.c ├── sdk_src │ ├── CMakeLists.txt │ ├── internal_inc │ │ ├── at_client.h │ │ ├── at_socket_inf.h │ │ ├── at_uart_hal.h │ │ ├── at_utils.h │ │ ├── data_template_action.h │ │ ├── data_template_client.h │ │ ├── data_template_client_common.h │ │ ├── data_template_client_json.h │ │ ├── data_template_event.h │ │ ├── gateway_common.h │ │ ├── json_parser.h │ │ ├── log_upload.h │ │ ├── mqtt_client.h │ │ ├── mqtt_client_net.h │ │ ├── network_interface.h │ │ ├── ota_client.h │ │ ├── ota_fetch.h │ │ ├── ota_lib.h │ │ ├── qcloud_iot_ca.h │ │ ├── qcloud_iot_common.h │ │ ├── qcloud_iot_device.h │ │ ├── utils_aes.h │ │ ├── utils_base64.h │ │ ├── utils_hmac.h │ │ ├── utils_httpc.h │ │ ├── utils_list.h │ │ ├── utils_md5.h │ │ ├── utils_param_check.h │ │ ├── utils_ringbuff.h │ │ ├── utils_sha1.h │ │ └── utils_timer.h │ ├── network │ │ ├── at_socket │ │ │ ├── at_client.c │ │ │ ├── at_socket_inf.c │ │ │ ├── at_utils.c │ │ │ └── network_at_tcp.c │ │ ├── network_interface.c │ │ ├── socket │ │ │ └── network_socket.c │ │ └── tls │ │ │ └── network_tls.c │ ├── protocol │ │ ├── http │ │ │ └── utils_httpc.c │ │ └── mqtt │ │ │ ├── mqtt_client.c │ │ │ ├── mqtt_client_common.c │ │ │ ├── mqtt_client_connect.c │ │ │ ├── mqtt_client_net.c │ │ │ ├── mqtt_client_publish.c │ │ │ ├── mqtt_client_subscribe.c │ │ │ ├── mqtt_client_unsubscribe.c │ │ │ └── mqtt_client_yield.c │ ├── services │ │ ├── data_template │ │ │ ├── data_template_aciton.c │ │ │ ├── data_template_client.c │ │ │ ├── data_template_client_common.c │ │ │ ├── data_template_client_json.c │ │ │ ├── data_template_client_manager.c │ │ │ └── data_template_event.c │ │ ├── dynreg │ │ │ └── dynreg.c │ │ ├── gateway │ │ │ ├── gateway_api.c │ │ │ └── gateway_common.c │ │ ├── log │ │ │ ├── log_mqtt.c │ │ │ └── log_upload.c │ │ ├── ota │ │ │ ├── ota_client.c │ │ │ ├── ota_fetch.c │ │ │ ├── ota_lib.c │ │ │ └── ota_mqtt.c │ │ └── system │ │ │ └── system_mqtt.c │ └── utils │ │ ├── json_parser.c │ │ ├── json_token.c │ │ ├── qcloud_iot_ca.c │ │ ├── qcloud_iot_device.c │ │ ├── qcloud_iot_log.c │ │ ├── string_utils.c │ │ ├── utils_aes.c │ │ ├── utils_base64.c │ │ ├── utils_getopt.c │ │ ├── utils_hmac.c │ │ ├── utils_list.c │ │ ├── utils_md5.c │ │ ├── utils_ringbuff.c │ │ ├── utils_sha1.c │ │ └── utils_timer.c └── tools │ ├── build_scripts │ ├── internal_make_funcs.mk │ ├── parse_make_settings.mk │ ├── rules-tests.mk │ ├── rules.mk │ ├── stats_static_lib.sh │ ├── update_gtest.sh │ └── update_mbedtls.sh │ ├── cmake_scripts │ ├── config.h.in │ └── convert.sh │ ├── codegen.py │ ├── example_config.json │ └── run-clang-tidy.py └── samples ├── data_template ├── action_config.c ├── data_config.c ├── data_template_sample.c └── events_config.c ├── dynreg_dev └── dynreg_dev_sample.c ├── gateway ├── gateway_sample.c └── sub_dev001.c ├── mqtt └── mqtt_sample.c ├── ota └── ota_mqtt_sample.c ├── raw_data └── raw_data_sample.c └── scenarized └── light_data_template_sample.c /docs/数据模板开发/数据模板代码生成.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 本文介绍基于物联开发平台 IoT Explorer 创建的数据模板如何生成模板代码。 3 | 4 | ## 数据模板创建 5 | 参阅[产品定义](https://cloud.tencent.com/document/product/1081/34739?!preview&!editLang=zh#.E6.95.B0.E6.8D.AE.E6.A8.A1.E6.9D.BF)创建数据模板 6 | 7 | ## 数据模板描述文件导出 8 | 数据模板描述文件是一个 JSON 格式的文件,描述了产品定义的属性、事件及其他信息,在平台导出此json文件,如下图示: 9 | ![](https://main.qcloudimg.com/raw/0951d7c3f540ca716442e08651a0efa5.jpg) 10 | 11 | ## 数据模板模板代码生成 12 | 将下载的json文件拷贝到tools目录,执行./codegen.py -c xx/config.json -d ../targetdir/ 命令,则会根据json文件在target目录生成所定义产品的数据模板及事件的配置文件,将这个生成的配置文件拷贝到data_template_sample.c的同级目录,data_template_sample.c示例了通用的数据模板处理框架,可以基于此框架添加业务逻辑。智能灯示例light_data_template_sample.c即是基于此框架的场景示例。 13 | 14 | ``` 15 | ./codegen.py -c light.json -d ../samples/data_template/ 16 | 加载 light.json 文件成功 17 | 文件 ../samples/data_template/data_config.c 生成成功 18 | 文件 ../samples/data_template/events_config.c 生成成功 19 | ``` -------------------------------------------------------------------------------- /docs/设备固件升级.md: -------------------------------------------------------------------------------- 1 | ## 操作场景 2 | 设备固件升级又称 OTA,是物联网通信服务的重要组成部分。当物联设备有新功能或者需要修复漏洞时,设备可以通过 OTA 服务快速的进行固件升级。 3 | 4 | 5 | ## 实现原理 6 | 固件升级的过程中,需要设备订阅下面两个 Topic 来实现与云端的通信,如下图所示: 7 | ![OTA topic](https://main.qcloudimg.com/raw/0046e2a294c541e109fc0b6829d180cc.jpg) 8 | 示例: 9 | ```php 10 | $ota/report/${productID}/${deviceName} 11 | 用于发布(上行)消息,设备上报版本号及下载、升级进度到云端 12 | $ota/update/${productID}/${deviceName} 13 | 用于订阅(下行)消息,设备接收云端的升级消息 14 | ``` 15 | 16 | 17 | ## 操作流程 18 | 设备的升级流程如下所示: 19 | ![OTA 时序图](https://main.qcloudimg.com/raw/a2f10ab90959a23b1675201b1e2311e0.jpg) 20 | 1. 设备上报当前版本号。设备端通过 MQTT 协议发布一条消息到 Topic `$ota/report/${productID/${deviceName}`,进行版本号的上报,消息为 json 格式,内容如下: 21 | ```json 22 | { 23 | "type": "report_version", 24 | "report":{ 25 | "version": "0.1" 26 | } 27 | } 28 | // type:消息类型 29 | // version:上报的版本号 30 | ``` 31 | 2. 然后您可以在控制台上传固件。 32 | 3. 在控制台将指定的设备升级到指定的版本。 33 | 4. 触发固件升级操作后,设备端会通过订阅的 Topic `$ota/update/${productID}/${deviceName}` 收到固件升级的消息,内容如下: 34 | ``` json 35 | { 36 | "file_size": 708482, 37 | "md5sum": "36eb5951179db14a631463a37a9322a2", 38 | "type": "update_firmware", 39 | "url": "https://ota-1255858890.cos.ap-guangzhou.myqcloud.com", 40 | "version": "0.2" 41 | } 42 | // type:消息类型为update_firmware 43 | // version:升级版本 44 | // url:下载固件的url 45 | // md5asum:固件的MD5值 46 | // file_size:固件大小,单位为字节 47 | ``` 48 | 5. 设备在收到固件升级的消息后,根据 URL 下载固件,下载的过程中设备 SDK 会通过 Topic `$ota/report/${productID}/${deviceName}`不断的上报下载进度,上报的内容如下: 49 | ```json 50 | { 51 | "type": "report_progress", 52 | "report":{ 53 | "progress":{ 54 | "state":"downloading", 55 | "percent":"10", 56 | "result_code":"0", 57 | "result_msg":"" 58 | }, 59 | "version": "0.2" 60 | } 61 | } 62 | // type:消息类型 63 | // state:状态为正在下载中 64 | // percent:当前下载进度,百分比 65 | ``` 66 | 6. 当设备下载完固件,设备需要通过 Topic `$ota/report/${productID}/${deviceName}`上报一条开始升级的消息,内容如下: 67 | ```json 68 | { 69 | "type": "report_progress", 70 | "report":{ 71 | "progress":{ 72 | "state":"burning", 73 | "result_code":"0", 74 | "result_msg":"" 75 | }, 76 | "version": "0.2" 77 | } 78 | } 79 | // type:消息类型 80 | // state:状态为烧制中 81 | ``` 82 | 7. 设备固件升级完成后,再向 Topic `$ota/report/${productID}/${deviceName}`上报升级成功消息,内容如下: 83 | ```json 84 | { 85 | "type": "report_progress", 86 | "report":{ 87 | "progress":{ 88 | "state":"done", 89 | "result_code":"0", 90 | "result_msg":"" 91 | }, 92 | "version": "0.2" 93 | } 94 | } 95 | // type:消息类型 96 | // state:状态为已完成 97 | ``` 98 | 99 | >!在下载固件或升级固件的过程中,如果失败,则通过 Topic `$ota/report/${productID}/${deviceName}`上报升级失败消息,内容如下: 100 | 101 | ```json 102 | { 103 | "type": "report_progress", 104 | "report":{ 105 | "progress":{ 106 | "state":"fail", 107 | "result_code":"-1", 108 | "result_msg":"time_out" 109 | }, 110 | "version": "0.2" 111 | } 112 | } 113 | // state:状态为失败 114 | // result_code:错误码,-1:下载超时;-2:文件不存在;-3:签名过期;-4:MD5不匹配;-5:更新固件失败 115 | // result_msg:错误消息 116 | ``` 117 | 118 | ## OTA断点续传 119 | 物联网设备有部分场景处于弱网环境,在这个场景下连接会不稳定,固件下载会中断的情况出现。如果每次都从0偏移开始下载固件,则弱网环境有可能一直无法完成全部固件下载,因此固件的断点续传功能特别必要。 120 | 121 | 断点续传就是从文件上次中断的地方开始重新下载或上传,要实现断点续传的功能,需要设备端记录固件下载的中断位置,同时记录下载固件的md5、文件大小、版本信息。 122 | 123 | 平台针对OTA中断的场景,设备侧report设备的版本,如果上报的版本号与要升级的目标版本号不一致,则平台会再次下发固件升级消息,设备获取到升级的目标固件的信息与本地记录的中断的固件信息比较,确定为同一固件后,基于断点继续下载。 124 | 125 | SDK提供的OTA sample示例了断点续传的断点记录及续传实现,示例是基于json文件实现记录描述,对于没有文件系统的修改这部分实现即可。 126 | 127 | 带断点续传的OTA升级流程如下,弱网环境下第3步到第6步有可能会多次执行,没有执行第7步,执行第3步,设备端都会收到第4步的消息。 128 | 129 | ![OTA 断点续传时序图](https://main.qcloudimg.com/raw/5d17e84352b59ea448fb95824ea53e6d.jpg) 130 | -------------------------------------------------------------------------------- /ports/rtthread/HAL_Timer_rtthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub available. 3 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 | 21 | #include 22 | #include 23 | #include "qcloud_iot_import.h" 24 | 25 | uint32_t HAL_GetTimeMs(void) 26 | { 27 | #if (RT_TICK_PER_SECOND == 1000) 28 | /* #define RT_TICK_PER_SECOND 1000 */ 29 | return (unsigned long)rt_tick_get(); 30 | #else 31 | unsigned long tick = 0; 32 | 33 | tick = rt_tick_get(); 34 | tick = tick * 1000; 35 | return (unsigned long)((tick + RT_TICK_PER_SECOND - 1)/RT_TICK_PER_SECOND); 36 | #endif 37 | 38 | } 39 | 40 | /*Get timestamp*/ 41 | long HAL_Timer_current_sec(void) 42 | { 43 | return HAL_GetTimeMs() / 1000; 44 | } 45 | 46 | char *HAL_Timer_current(char *time_str) 47 | { 48 | long time_sec; 49 | 50 | time_sec = HAL_Timer_current_sec(); 51 | memset(time_str, 0, 20); 52 | snprintf(time_str, 20, "%ld", time_sec); 53 | 54 | return time_str; 55 | } 56 | 57 | 58 | 59 | bool HAL_Timer_expired(Timer *timer) 60 | { 61 | uint32_t now_ts; 62 | 63 | now_ts = HAL_GetTimeMs(); 64 | 65 | 66 | return (now_ts > timer->end_time)?true:false; 67 | } 68 | 69 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 70 | { 71 | timer->end_time = HAL_GetTimeMs(); 72 | timer->end_time += timeout_ms; 73 | } 74 | 75 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 76 | { 77 | timer->end_time = HAL_GetTimeMs(); 78 | timer->end_time += timeout * 1000; 79 | } 80 | 81 | int HAL_Timer_remain(Timer *timer) 82 | { 83 | return (int)(timer->end_time - HAL_GetTimeMs()); 84 | } 85 | 86 | void HAL_Timer_init(Timer *timer) 87 | { 88 | timer->end_time = 0; 89 | } 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/.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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | } -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/LICENSE: -------------------------------------------------------------------------------- 1 | Tencent is pleased to support the open source community by making IoT Hub available. 2 | 3 | Copyright (C) 2016 THL A29 Limited, a Tencent company. 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. -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/README.md: -------------------------------------------------------------------------------- 1 | # 腾讯云物联网开发平台设备端 C-SDK 2 | 腾讯云物联网开发平台(IoT Explorer)设备端 C-SDK ,配合平台对设备数据模板化的定义,实现和云端基于数据模板协议的数据交互框架,开发者基于IoT_Explorer C-SDK数据模板框架,通过脚本自动生成模板代码,快速实现设备和平台、设备和应用之间的数据交互。 3 | 4 | ## IoT_Explorer C-SDK 架构 5 | 6 | #### 架构图 7 | 8 | ![framework](https://main.qcloudimg.com/raw/76fc3f15c4c91ea6cf7e496f25d5d572.jpg) 9 | 10 | #### 架构说明 11 | 12 | SDK分四层设计,从上至下分别为平台服务层、核心协议层、网络层、硬件抽象层。 13 | 14 | - 服务层 15 | 在网络协议层之上,实现了包括设备接入鉴权,设备影子,数据模板,网关,动态注册,日志上报和OTA等功能,并提供相关API接口给用户使用,关于服务层API说明,请参考doc目录文档[C-SDK_API及可变参数说明](https://github.com/tencentyun/qcloud-iot-explorer-sdk-embedded-c/blob/master/docs/C-SDK_API%E5%8F%8A%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E.md) 16 | 17 | - 协议层 18 | 设备端和IoT平台交互的网络协议包括MQTT/COAP/HTTP 19 | 20 | - 网络层 21 | 实现基于TLS/SSL(TLS/DTLS)方式,Bsd_socket(TCP/UDP)方式和AT_socket方式的网络协议栈,不同服务可根据需要使用不同的协议栈接口函数。 22 | 23 | - 硬件抽象层 24 | 实现对不同硬件平台的底层操作的抽象封装,需要针对具体的软硬件平台开展移植,分为必须实现和可选实现两部分HAL层接口。 25 | 26 | ## SDK 目录结构简介 27 | 28 | #### 目录结构及顶层文件简介 29 | 30 | | 名称 | 说明 | 31 | | ------------------ | ------------------------------------------------------------ | 32 | | CMakeLists.txt | cmake编译描述文件 | 33 | | CMakeSettings.json | visual studio下的cmake配置文件 | 34 | | cmake_build.sh | Linux下使用cmake的编译脚本 | 35 | | make.settings | Linux下使用Makefile直接编译的配置文件 | 36 | | Makefile | Linux下使用Makefile直接编译 | 37 | | device_info.json | 设备信息文件,当DEBUG_DEV_INFO_USED=OFF时,将从该文件解析出设备信息 | 38 | | docs | 文档目录,SDK使用说明文档。 | 39 | | external_libs | 第三方软件包组件,如mbedtls | 40 | | samples | 应用示例 | 41 | | include | 提供给用户使用的外部头文件 | 42 | | platform | 平台相关的源码文件,目前提供了针对不同OS(Linux/Windows/FreeRTOS/nonOS),TLS(mbedtls)以及AT模组下的实现。 | 43 | | sdk_src | SDK核心通信协议及服务代码 | 44 | | tools | SDK配套的编译及代码生成脚本工具 | 45 | 46 | ## SDK 编译方式说明 47 | 48 | C-SDK 支持三种编译方式: 49 | 50 | - cmake 方式 51 | - Makefile 方式 52 | - 代码抽取方式 53 | 54 | 编译方式以及编译配置选项的详细说明请参考docs目录文档[C-SDK_Build编译环境及配置选项说明](https://github.com/tencentyun/qcloud-iot-explorer-sdk-embedded-c/blob/master/docs/C-SDK_Build%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83%E5%8F%8A%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9%E8%AF%B4%E6%98%8E.md) 55 | 56 | ## SDK 快速体验 57 | 58 | 请参考docs目录文档 [IoT_Explorer开发平台快速入门](https://github.com/tencentyun/qcloud-iot-explorer-sdk-embedded-c/blob/master/docs/IoT_Explorer%E5%BC%80%E5%8F%91%E5%B9%B3%E5%8F%B0%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8.md) 59 | 60 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/certs/README.md: -------------------------------------------------------------------------------- 1 | 该目录用于存放两个文件: 2 | 1. 客户端证书文件; 3 | 2. 客户端私钥文件, 该文件需与客户端证书文件一一对应。 -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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/5/include -extra-arg=-I/usr/lib/gcc/x86_64-linux-gnu/5/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.py ${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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/device_info.json: -------------------------------------------------------------------------------- 1 | { 2 | "auth_mode":"KEY", 3 | 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 | "subdev_num":6, 19 | "subdev_list": 20 | [ 21 | {"sub_productId": "WPDA0S6S08", "sub_devName": "dev001"}, 22 | {"sub_productId": "WPDA0S6S08", "sub_devName": "dev002"}, 23 | {"sub_productId": "WPDA0S6S08", "sub_devName": "dev003"}, 24 | {"sub_productId": "Y8T6NB8DM0", "sub_devName": "test001"}, 25 | {"sub_productId": "Y8T6NB8DM0", "sub_devName": "test002"}, 26 | {"sub_productId": "Y8T6NB8DM0", "sub_devName": "test003"} 27 | ] 28 | }, 29 | 30 | "region":"china" 31 | } -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/docs/Device_Type设备类型说明.md: -------------------------------------------------------------------------------- 1 | # 设备联网类型说明 2 | 本文对连接腾讯云物联网平台(下文以 IoT Explorer 为例)的设备类型进行说明,并阐明各设备类型如何移植C-SDK。 3 | 4 | ## IoT设备联网类型 5 | IoT设备首先得具备接入网络的能力,接入网络必须要有TCP/IP协议栈,从TCP/IP协议栈承载的载体区分,IoT设备分为如下三类: 6 | 7 | **类型一**: TCP/IP协议栈跑在主芯片上,主芯片的处理能力和资源较丰富,譬如路由器,本文称作 资源丰富类 IoT设备。 8 | 9 | ![soc](https://main.qcloudimg.com/raw/b8b8c257ff2a0862fccee025ac361883.jpg) 10 | 11 | **类型二**: TCP/IP协议栈跑在通信模组上,主芯片处理能力和资源特别有限,譬如STM32F103系列,本文称作 资源受限类 IoT设备。 12 | ![mcu+module](https://main.qcloudimg.com/raw/aa148085175ebc615c4bc6fa3e483188.jpg) 13 | 14 | **类型三**: TCP/IP协议栈跑在网关上,设备本身并不能直接接入网络,通过有线(485/CAN等)或无线(Ble/ZigBee等)的方式和网关交互,网关(设备类型一或设备类型二)再将数据转发到服务端,这类设备本文称作区域通信类设备。 15 | ![lan](https://main.qcloudimg.com/raw/31fa38d9eb941fc48041ae18ca1860f6.jpg) 16 | 17 | 18 | ## 不同联网类型的设备接入方式 19 | 20 | ### 资源丰富类设备接入 21 | C-SDK可以在 Linux 和 Windows 环境直接编译并运行示例,请参照[C-SDK_Build编译环境及配置选项说明]()说明。针对常见的FreeRTOS+lwIP的场景,我们也提供了HAL层的示例实现。具体参见[FreeRTOS+lwIP平台移植说明]()。 22 | 23 | ### 资源受限类设备接入 24 | 资源受限类设备,借助于通信模组实现网络访问,即MCU+模组方式。模组一般是蜂窝模组(2/3/4/5G)或者WIFI模组,市面可选的模组非常之多,各家的AT指令也各不一样,为此我们提供两种方式实现平台接入。 25 | - 一种是基于SDK提供的AT_Socket框架,基于模组的通用TCP指令,参照at_device目录下的已支持的模组,实现AT_Device驱动的结构体**at_device_op_t**实现对应的驱动接口即可,具体参见[MCU+通用TCP_AT模组移植]()。 26 | - 另一种方式是,我们和主流的模组厂商做了深度合作,将SDK的核心协议已移植到模组中,模组对外封装统一的腾讯云AT指令,同时我们对MCU提供实现和定制模组交互的SDK,,具体参见[MCU+腾讯云定制AT模组]()。 27 | 28 | ### 区域通信类设备接入 29 | 对于区域通信类设备,网关需要实现SDK的移植,SDK针对网关提供对应的协议逻辑代理子设备上线、下线及协议数据交互,网关实现和子设备通信方式和数据格式可根据场景定义,网关将子设备数据及平台下行数据做响应转换后实现上传下达。网关设备归属于类型一或类型二设备,可以对应参照实现SDK移植。 -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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平台搭建一个工程示例 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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 并接入腾讯云物联网平台(以IoT Explorer为例)。 4 | 5 | ## 系统框图 6 | ![mcu+module](https://main.qcloudimg.com/raw/aa148085175ebc615c4bc6fa3e483188.jpg) 7 | 8 | ## 移植步骤 9 | ![port_flow](https://main.qcloudimg.com/raw/3717052f47405e66a754f2f8594c6c84.jpg) 10 | 11 | ### 1. 下载最新版本设备端 [C-SDK](https://github.com/tencentyun/qcloud-iot-sdk-embedded-c)。 12 | 13 | ### 2. SDK功能配置及代码抽取 14 | - 使用通用TCP模组编译配置选项配置如下: 15 | 16 | | 名称 | 配置 | 说明 | 17 | | :------------------------------- | ------------- | ------------------------------------------------------------ | 18 | | BUILD_TYPE | debug/release,根据需要设置 | 19 | | EXTRACT_SRC | ON | 使能代码抽取 | 20 | | COMPILE_TOOLS | gcc/MSVC | 根据需要设置,IDE情况不关注 | 21 | | PLATFORM | linux/windows | 根据需要设置,IDE情况不关注 | 22 | | FEATURE_OTA_COMM_ENABLED | ON/OFF | 根据需要设置 | 23 | | FEATURE_AUTH_MODE | KEY | 资源受限设备认证方式建议选秘钥认证 | 24 | | FEATURE_AUTH_WITH_NOTLS | ON/OFF | 根据需要是否使能TLS | 25 | | FEATURE_EVENT_POST_ENABLED | ON/OFF | 根据需要是否使能事件上报 | 26 | | FEATURE_AT_TCP_ENABLED | ON | AT模组TCP功能开关 | 27 | | FEATURE_AT_UART_RECV_IRQ | ON | AT模组中断接受功能开关 | 28 | | FEATURE_AT_OS_USED | ON | AT模组多线程功能开关 | 29 | | FEATURE_AT_DEBUG | OFF | 默认关闭AT模组调试功能,有调试需要再打开| 30 | 31 | - 参考文档[C-SDK_Build编译环境及配置选项说明]()抽取代码 32 | 33 | - 将抽取的代码目录作为通信组件放在类似 RTOS、FATFS 的第三方组件的同级目录,系统代码框架大体如下: 34 | ![](https://main.qcloudimg.com/raw/5e3da49ac27e57d72fd6f6a70bb98547.jpg) 35 | 36 | ### 3. 数据模板模板代码生成 37 | 对于IoT_Explorer产品可以参考[IoT_Explorer/Data_template数据模板代码生成]() 38 | 对于IoT_Hub产品,可跳过这一步 39 | 40 | ### 4. HAL 层移植 41 | 42 | 参见[C-SDK_Porting跨平台移植概述]() 43 | 对于网络相关的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提供了底层接口实现,供移植到其他通讯模组时作为参考。 44 | 45 | ### 5. 业务逻辑开发 46 | 47 | 对于IoT_Explorer产品,可以参考[IoT_Explorer/Data_template数据模板应用开发]()实现具体业务场景下的业务逻辑开发。 48 | 对于IoT_Hub产品,可以参考IoT_Hub目录下的例程。 49 | 50 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 并接入腾讯云物联网平台(以IoT Explorer为例)。 4 | 相较于有RTOS场景,at_socket网络接收数据的处理会有差异,应用层需要周期性的调用**IOT_MQTT_Yield**来接收服务端下行数据,错过接收窗口则会存在数据丢失的情况,所以在业务逻辑较为复杂的场景建议使用RTOS,通过配置 FEATURE_AT_OS_USED = OFF选择无OS方式。 5 | 6 | ## 系统框图 7 | ![mcu+module](https://main.qcloudimg.com/raw/aa148085175ebc615c4bc6fa3e483188.jpg) 8 | 9 | ## 移植步骤 10 | ![port_flow](https://main.qcloudimg.com/raw/3717052f47405e66a754f2f8594c6c84.jpg) 11 | 12 | ### 1. 下载最新版本设备端 [C-SDK](https://github.com/tencentyun/qcloud-iot-sdk-embedded-c)。 13 | 14 | ### 2. SDK功能配置及代码抽取 15 | - 无RTOS使用通用TCP模组编译配置选项配置如下: 16 | 17 | | 名称 | 配置 | 说明 | 18 | | :------------------------------- | ------------- | ------------------------------------------------------------ | 19 | | BUILD_TYPE | debug/release,根据需要设置 | 20 | | EXTRACT_SRC | ON | 使能代码抽取 | 21 | | COMPILE_TOOLS | gcc/MSVC | 根据需要设置,IDE情况不关注 | 22 | | PLATFORM | linux/windows | 根据需要设置,IDE情况不关注 | 23 | | FEATURE_OTA_COMM_ENABLED | ON/OFF | 根据需要设置 | 24 | | FEATURE_AUTH_MODE | KEY | 资源受限设备认证方式建议选秘钥认证 | 25 | | FEATURE_AUTH_WITH_NOTLS | ON/OFF | 根据需要是否使能TLS | 26 | | FEATURE_EVENT_POST_ENABLED | ON/OFF | 根据需要是否使能事件上报 | 27 | | FEATURE_AT_TCP_ENABLED | ON | 使能at_socket组件 | 28 | | FEATURE_AT_UART_RECV_IRQ | ON | 使能AT串口中断接收 | 29 | | FEATURE_AT_OS_USED | OFF | at_socket组件无RTOS环境使用 | 30 | | FEATURE_AT_DEBUG | OFF | 默认关闭AT模组调试功能,有调试需要再打开| 31 | 32 | - 参考文档[C-SDK_Build编译环境及配置选项说明]()抽取代码 33 | 34 | - 将抽取的代码目录作为通信组件放在类似 RTOS、FATFS 的第三方组件的同级目录,系统代码框架大体如下: 35 | ![](https://main.qcloudimg.com/raw/5e3da49ac27e57d72fd6f6a70bb98547.jpg) 36 | 37 | ### 3. 数据模板模板代码生成 38 | 对于IoT_Explorer产品可以参考[IoT_Explorer/Data_template数据模板代码生成]() 39 | 对于IoT_Hub产品,可跳过这一步 40 | 41 | ### 4. HAL 层移植 42 | 43 | 参见[C-SDK_Porting跨平台移植概述]() 44 | 45 | 对于网络相关的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 实现目标平台的移植。 46 | 47 | ### 5. 业务逻辑开发 48 | 49 | 对于IoT_Explorer产品,可以参考[IoT_Explorer/Data_template数据模板应用开发]()实现具体业务场景下的业务逻辑开发。 50 | 对于IoT_Hub产品,可以参考IoT_Hub目录下的例程。 51 | 52 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/docs/数据模板开发/数据模板代码生成.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 本文介绍基于物联开发平台 IoT Explorer 创建的数据模板如何生成模板代码。 3 | 4 | ## 数据模板创建 5 | 参阅[产品定义](https://cloud.tencent.com/document/product/1081/34739?!preview&!editLang=zh#.E6.95.B0.E6.8D.AE.E6.A8.A1.E6.9D.BF)创建数据模板 6 | 7 | ## 数据模板描述文件导出 8 | 数据模板描述文件是一个 JSON 格式的文件,描述了产品定义的属性、事件及其他信息,在平台导出此json文件,如下图示: 9 | ![](https://main.qcloudimg.com/raw/0951d7c3f540ca716442e08651a0efa5.jpg) 10 | 11 | ## 数据模板模板代码生成 12 | 将下载的json文件拷贝到tools目录,执行./codegen.py -c xx/config.json -d ../targetdir/ 命令,则会根据json文件在target目录生成所定义产品的数据模板及事件的配置文件,将这个生成的配置文件拷贝到data_template_sample.c的同级目录,data_template_sample.c示例了通用的数据模板处理框架,可以基于此框架添加业务逻辑。智能灯示例light_data_template_sample.c即是基于此框架的场景示例。 13 | 14 | ``` 15 | ./codegen.py -c light.json -d ../samples/data_template/ 16 | 加载 light.json 文件成功 17 | 文件 ../samples/data_template/data_config.c 生成成功 18 | 文件 ../samples/data_template/events_config.c 生成成功 19 | ``` -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/docs/设备固件升级.md: -------------------------------------------------------------------------------- 1 | ## 操作场景 2 | 设备固件升级又称 OTA,是物联网通信服务的重要组成部分。当物联设备有新功能或者需要修复漏洞时,设备可以通过 OTA 服务快速的进行固件升级。 3 | 4 | 5 | ## 实现原理 6 | 固件升级的过程中,需要设备订阅下面两个 Topic 来实现与云端的通信,如下图所示: 7 | ![OTA topic](https://main.qcloudimg.com/raw/0046e2a294c541e109fc0b6829d180cc.jpg) 8 | 示例: 9 | ```php 10 | $ota/report/${productID}/${deviceName} 11 | 用于发布(上行)消息,设备上报版本号及下载、升级进度到云端 12 | $ota/update/${productID}/${deviceName} 13 | 用于订阅(下行)消息,设备接收云端的升级消息 14 | ``` 15 | 16 | 17 | ## 操作流程 18 | 设备的升级流程如下所示: 19 | ![OTA 时序图](https://main.qcloudimg.com/raw/a2f10ab90959a23b1675201b1e2311e0.jpg) 20 | 1. 设备上报当前版本号。设备端通过 MQTT 协议发布一条消息到 Topic `$ota/report/${productID/${deviceName}`,进行版本号的上报,消息为 json 格式,内容如下: 21 | ```json 22 | { 23 | "type": "report_version", 24 | "report":{ 25 | "version": "0.1" 26 | } 27 | } 28 | // type:消息类型 29 | // version:上报的版本号 30 | ``` 31 | 2. 然后您可以在控制台上传固件。 32 | 3. 在控制台将指定的设备升级到指定的版本。 33 | 4. 触发固件升级操作后,设备端会通过订阅的 Topic `$ota/update/${productID}/${deviceName}` 收到固件升级的消息,内容如下: 34 | ``` json 35 | { 36 | "file_size": 708482, 37 | "md5sum": "36eb5951179db14a631463a37a9322a2", 38 | "type": "update_firmware", 39 | "url": "https://ota-1255858890.cos.ap-guangzhou.myqcloud.com", 40 | "version": "0.2" 41 | } 42 | // type:消息类型为update_firmware 43 | // version:升级版本 44 | // url:下载固件的url 45 | // md5asum:固件的MD5值 46 | // file_size:固件大小,单位为字节 47 | ``` 48 | 5. 设备在收到固件升级的消息后,根据 URL 下载固件,下载的过程中设备 SDK 会通过 Topic `$ota/report/${productID}/${deviceName}`不断的上报下载进度,上报的内容如下: 49 | ```json 50 | { 51 | "type": "report_progress", 52 | "report":{ 53 | "progress":{ 54 | "state":"downloading", 55 | "percent":"10", 56 | "result_code":"0", 57 | "result_msg":"" 58 | }, 59 | "version": "0.2" 60 | } 61 | } 62 | // type:消息类型 63 | // state:状态为正在下载中 64 | // percent:当前下载进度,百分比 65 | ``` 66 | 6. 当设备下载完固件,设备需要通过 Topic `$ota/report/${productID}/${deviceName}`上报一条开始升级的消息,内容如下: 67 | ```json 68 | { 69 | "type": "report_progress", 70 | "report":{ 71 | "progress":{ 72 | "state":"burning", 73 | "result_code":"0", 74 | "result_msg":"" 75 | }, 76 | "version": "0.2" 77 | } 78 | } 79 | // type:消息类型 80 | // state:状态为烧制中 81 | ``` 82 | 7. 设备固件升级完成后,再向 Topic `$ota/report/${productID}/${deviceName}`上报升级成功消息,内容如下: 83 | ```json 84 | { 85 | "type": "report_progress", 86 | "report":{ 87 | "progress":{ 88 | "state":"done", 89 | "result_code":"0", 90 | "result_msg":"" 91 | }, 92 | "version": "0.2" 93 | } 94 | } 95 | // type:消息类型 96 | // state:状态为已完成 97 | ``` 98 | 99 | >!在下载固件或升级固件的过程中,如果失败,则通过 Topic `$ota/report/${productID}/${deviceName}`上报升级失败消息,内容如下: 100 | 101 | ```json 102 | { 103 | "type": "report_progress", 104 | "report":{ 105 | "progress":{ 106 | "state":"fail", 107 | "result_code":"-1", 108 | "result_msg":"time_out" 109 | }, 110 | "version": "0.2" 111 | } 112 | } 113 | // state:状态为失败 114 | // result_code:错误码,-1:下载超时;-2:文件不存在;-3:签名过期;-4:MD5不匹配;-5:更新固件失败 115 | // result_msg:错误消息 116 | ``` 117 | 118 | ## OTA断点续传 119 | 物联网设备有部分场景处于弱网环境,在这个场景下连接会不稳定,固件下载会中断的情况出现。如果每次都从0偏移开始下载固件,则弱网环境有可能一直无法完成全部固件下载,因此固件的断点续传功能特别必要。 120 | 121 | 断点续传就是从文件上次中断的地方开始重新下载或上传,要实现断点续传的功能,需要设备端记录固件下载的中断位置,同时记录下载固件的md5、文件大小、版本信息。 122 | 123 | 平台针对OTA中断的场景,设备侧report设备的版本,如果上报的版本号与要升级的目标版本号不一致,则平台会再次下发固件升级消息,设备获取到升级的目标固件的信息与本地记录的中断的固件信息比较,确定为同一固件后,基于断点继续下载。 124 | 125 | SDK提供的OTA sample示例了断点续传的断点记录及续传实现,示例是基于json文件实现记录描述,对于没有文件系统的修改这部分实现即可。 126 | 127 | 带断点续传的OTA升级流程如下,弱网环境下第3步到第6步有可能会多次执行,没有执行第7步,执行第3步,设备端都会收到第4步的消息。 128 | 129 | ![OTA 断点续传时序图](https://main.qcloudimg.com/raw/5d17e84352b59ea448fb95824ea53e6d.jpg) 130 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/external_libs/mbedtls/include/mbedtls/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file error.h 3 | * 4 | * \brief Error to string translation 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_ERROR_H 24 | #define MBEDTLS_ERROR_H 25 | 26 | #include 27 | 28 | /** 29 | * Error code layout. 30 | * 31 | * Currently we try to keep all error codes within the negative space of 16 32 | * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In 33 | * addition we'd like to give two layers of information on the error if 34 | * possible. 35 | * 36 | * For that purpose the error codes are segmented in the following manner: 37 | * 38 | * 16 bit error code bit-segmentation 39 | * 40 | * 1 bit - Unused (sign bit) 41 | * 3 bits - High level module ID 42 | * 5 bits - Module-dependent error code 43 | * 7 bits - Low level module errors 44 | * 45 | * For historical reasons, low-level error codes are divided in even and odd, 46 | * even codes were assigned first, and -1 is reserved for other errors. 47 | * 48 | * Low-level module errors (0x0002-0x007E, 0x0003-0x007F) 49 | * 50 | * Module Nr Codes assigned 51 | * MPI 7 0x0002-0x0010 52 | * GCM 2 0x0012-0x0014 53 | * BLOWFISH 2 0x0016-0x0018 54 | * THREADING 3 0x001A-0x001E 55 | * AES 2 0x0020-0x0022 56 | * CAMELLIA 2 0x0024-0x0026 57 | * XTEA 1 0x0028-0x0028 58 | * BASE64 2 0x002A-0x002C 59 | * OID 1 0x002E-0x002E 0x000B-0x000B 60 | * PADLOCK 1 0x0030-0x0030 61 | * DES 1 0x0032-0x0032 62 | * CTR_DBRG 4 0x0034-0x003A 63 | * ENTROPY 3 0x003C-0x0040 0x003D-0x003F 64 | * NET 11 0x0042-0x0052 0x0043-0x0045 65 | * ASN1 7 0x0060-0x006C 66 | * PBKDF2 1 0x007C-0x007C 67 | * HMAC_DRBG 4 0x0003-0x0009 68 | * CCM 2 0x000D-0x000F 69 | * 70 | * High-level module nr (3 bits - 0x0...-0x7...) 71 | * Name ID Nr of Errors 72 | * PEM 1 9 73 | * PKCS#12 1 4 (Started from top) 74 | * X509 2 19 75 | * PKCS5 2 4 (Started from top) 76 | * DHM 3 9 77 | * PK 3 14 (Started from top) 78 | * RSA 4 9 79 | * ECP 4 8 (Started from top) 80 | * MD 5 4 81 | * CIPHER 6 6 82 | * SSL 6 17 (Started from top) 83 | * SSL 7 31 84 | * 85 | * Module dependent error code (5 bits 0x.00.-0x.F8.) 86 | */ 87 | 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | 92 | /** 93 | * \brief Translate a mbed TLS error code into a string representation, 94 | * Result is truncated if necessary and always includes a terminating 95 | * null byte. 96 | * 97 | * \param errnum error code 98 | * \param buffer buffer to place representation in 99 | * \param buflen length of the buffer 100 | */ 101 | void mbedtls_strerror( int errnum, char *buffer, size_t buflen ); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* error.h */ 108 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/external_libs/mbedtls/include/mbedtls/md_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md_internal.h 3 | * 4 | * \brief Message digest wrappers. 5 | * 6 | * \warning This in an internal header. Do not include directly. 7 | * 8 | * \author Adriaan de Jong 9 | * 10 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 11 | * SPDX-License-Identifier: Apache-2.0 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 14 | * not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | * This file is part of mbed TLS (https://tls.mbed.org) 26 | */ 27 | #ifndef MBEDTLS_MD_WRAP_H 28 | #define MBEDTLS_MD_WRAP_H 29 | 30 | #if !defined(MBEDTLS_CONFIG_FILE) 31 | #include "config.h" 32 | #else 33 | #include MBEDTLS_CONFIG_FILE 34 | #endif 35 | 36 | #include "md.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * Message digest information. 44 | * Allows message digest functions to be called in a generic way. 45 | */ 46 | struct mbedtls_md_info_t 47 | { 48 | /** Digest identifier */ 49 | mbedtls_md_type_t type; 50 | 51 | /** Name of the message digest */ 52 | const char * name; 53 | 54 | /** Output length of the digest function in bytes */ 55 | int size; 56 | 57 | /** Block length of the digest function in bytes */ 58 | int block_size; 59 | 60 | /** Digest initialisation function */ 61 | void (*starts_func)( void *ctx ); 62 | 63 | /** Digest update function */ 64 | void (*update_func)( void *ctx, const unsigned char *input, size_t ilen ); 65 | 66 | /** Digest finalisation function */ 67 | void (*finish_func)( void *ctx, unsigned char *output ); 68 | 69 | /** Generic digest function */ 70 | void (*digest_func)( const unsigned char *input, size_t ilen, 71 | unsigned char *output ); 72 | 73 | /** Allocate a new context */ 74 | void * (*ctx_alloc_func)( void ); 75 | 76 | /** Free the given context */ 77 | void (*ctx_free_func)( void *ctx ); 78 | 79 | /** Clone state from a context */ 80 | void (*clone_func)( void *dst, const void *src ); 81 | 82 | /** Internal use only */ 83 | void (*process_func)( void *ctx, const unsigned char *input ); 84 | }; 85 | 86 | #if defined(MBEDTLS_MD2_C) 87 | extern const mbedtls_md_info_t mbedtls_md2_info; 88 | #endif 89 | #if defined(MBEDTLS_MD4_C) 90 | extern const mbedtls_md_info_t mbedtls_md4_info; 91 | #endif 92 | #if defined(MBEDTLS_MD5_C) 93 | extern const mbedtls_md_info_t mbedtls_md5_info; 94 | #endif 95 | #if defined(MBEDTLS_RIPEMD160_C) 96 | extern const mbedtls_md_info_t mbedtls_ripemd160_info; 97 | #endif 98 | #if defined(MBEDTLS_SHA1_C) 99 | extern const mbedtls_md_info_t mbedtls_sha1_info; 100 | #endif 101 | #if defined(MBEDTLS_SHA256_C) 102 | extern const mbedtls_md_info_t mbedtls_sha224_info; 103 | extern const mbedtls_md_info_t mbedtls_sha256_info; 104 | #endif 105 | #if defined(MBEDTLS_SHA512_C) 106 | extern const mbedtls_md_info_t mbedtls_sha384_info; 107 | extern const mbedtls_md_info_t mbedtls_sha512_info; 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* MBEDTLS_MD_WRAP_H */ 115 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/external_libs/mbedtls/include/mbedtls/padlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file padlock.h 3 | * 4 | * \brief VIA PadLock ACE for HW encryption/decryption supported by some 5 | * processors 6 | * 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 8 | * SPDX-License-Identifier: Apache-2.0 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 11 | * not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * 22 | * This file is part of mbed TLS (https://tls.mbed.org) 23 | */ 24 | #ifndef MBEDTLS_PADLOCK_H 25 | #define MBEDTLS_PADLOCK_H 26 | 27 | #include "aes.h" 28 | 29 | #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ 30 | 31 | #if defined(__has_feature) 32 | #if __has_feature(address_sanitizer) 33 | #define MBEDTLS_HAVE_ASAN 34 | #endif 35 | #endif 36 | 37 | /* Some versions of ASan result in errors about not enough registers */ 38 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \ 39 | !defined(MBEDTLS_HAVE_ASAN) 40 | 41 | #ifndef MBEDTLS_HAVE_X86 42 | #define MBEDTLS_HAVE_X86 43 | #endif 44 | 45 | #include 46 | 47 | #define MBEDTLS_PADLOCK_RNG 0x000C 48 | #define MBEDTLS_PADLOCK_ACE 0x00C0 49 | #define MBEDTLS_PADLOCK_PHE 0x0C00 50 | #define MBEDTLS_PADLOCK_PMM 0x3000 51 | 52 | #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15)) 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /** 59 | * \brief PadLock detection routine 60 | * 61 | * \param feature The feature to detect 62 | * 63 | * \return 1 if CPU has support for the feature, 0 otherwise 64 | */ 65 | int mbedtls_padlock_has_support( int feature ); 66 | 67 | /** 68 | * \brief PadLock AES-ECB block en(de)cryption 69 | * 70 | * \param ctx AES context 71 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 72 | * \param input 16-byte input block 73 | * \param output 16-byte output block 74 | * 75 | * \return 0 if success, 1 if operation failed 76 | */ 77 | int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, 78 | int mode, 79 | const unsigned char input[16], 80 | unsigned char output[16] ); 81 | 82 | /** 83 | * \brief PadLock AES-CBC buffer en(de)cryption 84 | * 85 | * \param ctx AES context 86 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 87 | * \param length length of the input data 88 | * \param iv initialization vector (updated after use) 89 | * \param input buffer holding the input data 90 | * \param output buffer holding the output data 91 | * 92 | * \return 0 if success, 1 if operation failed 93 | */ 94 | int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, 95 | int mode, 96 | size_t length, 97 | unsigned char iv[16], 98 | const unsigned char *input, 99 | unsigned char *output ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* HAVE_X86 */ 106 | 107 | #endif /* padlock.h */ 108 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/external_libs/mbedtls/include/mbedtls/pkcs5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pkcs5.h 3 | * 4 | * \brief PKCS#5 functions 5 | * 6 | * \author Mathias Olsson 7 | * 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * This file is part of mbed TLS (https://tls.mbed.org) 24 | */ 25 | #ifndef MBEDTLS_PKCS5_H 26 | #define MBEDTLS_PKCS5_H 27 | 28 | #include "asn1.h" 29 | #include "md.h" 30 | 31 | #include 32 | #include 33 | 34 | #define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */ 35 | #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */ 36 | #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */ 37 | #define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */ 38 | 39 | #define MBEDTLS_PKCS5_DECRYPT 0 40 | #define MBEDTLS_PKCS5_ENCRYPT 1 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** 47 | * \brief PKCS#5 PBES2 function 48 | * 49 | * \param pbe_params the ASN.1 algorithm parameters 50 | * \param mode either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT 51 | * \param pwd password to use when generating key 52 | * \param pwdlen length of password 53 | * \param data data to process 54 | * \param datalen length of data 55 | * \param output output buffer 56 | * 57 | * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails. 58 | */ 59 | int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, 60 | const unsigned char *pwd, size_t pwdlen, 61 | const unsigned char *data, size_t datalen, 62 | unsigned char *output ); 63 | 64 | /** 65 | * \brief PKCS#5 PBKDF2 using HMAC 66 | * 67 | * \param ctx Generic HMAC context 68 | * \param password Password to use when generating key 69 | * \param plen Length of password 70 | * \param salt Salt to use when generating key 71 | * \param slen Length of salt 72 | * \param iteration_count Iteration count 73 | * \param key_length Length of generated key in bytes 74 | * \param output Generated key. Must be at least as big as key_length 75 | * 76 | * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails. 77 | */ 78 | int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password, 79 | size_t plen, const unsigned char *salt, size_t slen, 80 | unsigned int iteration_count, 81 | uint32_t key_length, unsigned char *output ); 82 | 83 | /** 84 | * \brief Checkup routine 85 | * 86 | * \return 0 if successful, or 1 if the test failed 87 | */ 88 | int mbedtls_pkcs5_self_test( int verbose ); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* pkcs5.h */ 95 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/external_libs/mbedtls/include/mbedtls/ssl_cookie.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ssl_cookie.h 3 | * 4 | * \brief DTLS cookie callbacks implementation 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_SSL_COOKIE_H 24 | #define MBEDTLS_SSL_COOKIE_H 25 | 26 | #include "ssl.h" 27 | 28 | #if defined(MBEDTLS_THREADING_C) 29 | #include "threading.h" 30 | #endif 31 | 32 | /** 33 | * \name SECTION: Module settings 34 | * 35 | * The configuration options you can set for this module are in this section. 36 | * Either change them in config.h or define them on the compiler command line. 37 | * \{ 38 | */ 39 | #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT 40 | #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ 41 | #endif 42 | 43 | /* \} name SECTION: Module settings */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | * \brief Context for the default cookie functions. 51 | */ 52 | typedef struct 53 | { 54 | mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */ 55 | #if !defined(MBEDTLS_HAVE_TIME) 56 | unsigned long serial; /*!< serial number for expiration */ 57 | #endif 58 | unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME, 59 | or in number of tickets issued */ 60 | 61 | #if defined(MBEDTLS_THREADING_C) 62 | mbedtls_threading_mutex_t mutex; 63 | #endif 64 | } mbedtls_ssl_cookie_ctx; 65 | 66 | /** 67 | * \brief Initialize cookie context 68 | */ 69 | void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx ); 70 | 71 | /** 72 | * \brief Setup cookie context (generate keys) 73 | */ 74 | int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx, 75 | int (*f_rng)(void *, unsigned char *, size_t), 76 | void *p_rng ); 77 | 78 | /** 79 | * \brief Set expiration delay for cookies 80 | * (Default MBEDTLS_SSL_COOKIE_TIMEOUT) 81 | * 82 | * \param ctx Cookie contex 83 | * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies 84 | * issued in the meantime. 85 | * 0 to disable expiration (NOT recommended) 86 | */ 87 | void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay ); 88 | 89 | /** 90 | * \brief Free cookie context 91 | */ 92 | void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx ); 93 | 94 | /** 95 | * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t 96 | */ 97 | mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write; 98 | 99 | /** 100 | * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t 101 | */ 102 | mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check; 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* ssl_cookie.h */ 109 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/config.h: -------------------------------------------------------------------------------- 1 | /* #undef AUTH_MODE_CERT */ 2 | //#define AUTH_MODE_KEY 3 | /* #undef AUTH_WITH_NOTLS */ 4 | /* #undef GATEWAY_ENABLED */ 5 | /* #undef COAP_COMM_ENABLED */ 6 | //#define OTA_MQTT_CHANNEL 7 | /* #undef SYSTEM_COMM */ 8 | /* #undef EVENT_POST_ENABLED */ 9 | /* #undef ACTION_ENABLED */ 10 | //#define DEV_DYN_REG_ENABLED 11 | /* #undef LOG_UPLOAD */ 12 | /* #undef IOT_DEBUG */ 13 | /* #undef DEBUG_DEV_INFO_USED */ 14 | /* #undef AT_TCP_ENABLED */ 15 | /* #undef AT_UART_RECV_IRQ */ 16 | /* #undef AT_OS_USED */ 17 | /* #undef AT_DEBUG */ 18 | //#define OTA_USE_HTTPS 19 | /* #undef GATEWAY_ENABLED */ 20 | /* #undef MULTITHREAD_ENABLED */ 21 | /* #undef GATEWAY_DYN_BIND_SUBDEV_ENABLED */ 22 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/exports/qcloud_iot_export_dynreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QLCOUD_IOT_EXPORT_DYNREG_H_ 22 | #define QLCOUD_IOT_EXPORT_DYNREG_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "qcloud_iot_export.h" 29 | 30 | /** 31 | * @brief Do dynamic register/create device 32 | * 33 | * @param pDevInfo In: device info with [ProductId, ProductKey, DeviceName] 34 | * Out: device info with [ProductId, DeviceName, 35 | * DeviceSecret or Device cert/key file] 36 | * 37 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 38 | */ 39 | int IOT_DynReg_Device(DeviceInfo *pDevInfo); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif // QLCOUD_IOT_EXPORT_DYNREG_H_ -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/exports/qcloud_iot_export_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_EXPORT_SYSTEM_H_ 22 | #define QCLOUD_IOT_EXPORT_SYSTEM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define IP_MAX_NUM 10 29 | #define ONE_IP_MAX_LEN 24 30 | 31 | typedef enum{ 32 | eRESOURCE_TIME = 0, 33 | eRESOURCE_IP, 34 | }eSysResourcType; 35 | 36 | /** 37 | * @brief Get domain ip list for dns disaster recovery 38 | * 39 | * @param pClient MQTTClient pointer 40 | * @param eType type of sys resource to get 41 | * @param usrArg usr arg to return the target resource 42 | * @return QCLOUD_RET_SUCCESS for success 43 | * otherwise, failure 44 | */ 45 | int IOT_Get_Sys_Resource(void* pClient, eSysResourcType eType, DeviceInfo *pDevInfo, void *usrArg); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* QCLOUD_IOT_EXPORT_COAP_H_ */ -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 PLATFORM_H_ 22 | #define PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define PATH_MAX 4096 29 | /* Max size of cert/key file full path */ 30 | #define FILE_PATH_MAX_LEN 256 31 | 32 | #ifdef WIN32 33 | #include 34 | #include 35 | #include 36 | typedef unsigned long ssize_t; 37 | #define getcwd(buffer, len) _getcwd(buffer, len) 38 | #endif 39 | 40 | #if defined(__linux__) 41 | #include 42 | #include 43 | //#include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif /* PLATFORM_H_ */ 58 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/qcloud_iot_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_EXPORT_H_ 22 | #define QCLOUD_IOT_EXPORT_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "config.h" 29 | #include "platform.h" 30 | 31 | /* IoT C-SDK version info */ 32 | #define QCLOUD_IOT_DEVICE_SDK_VERSION "3.1.3" 33 | 34 | /**************** QCloud IoT C-SDK constants begin ************************/ 35 | 36 | /* MAX size of client ID */ 37 | #define MAX_SIZE_OF_CLIENT_ID (80) 38 | 39 | /* MAX size of product ID */ 40 | #define MAX_SIZE_OF_PRODUCT_ID (10) 41 | 42 | /* MAX size of product secret */ 43 | #define MAX_SIZE_OF_PRODUCT_SECRET (32) 44 | 45 | /* MAX size of device name */ 46 | #define MAX_SIZE_OF_DEVICE_NAME (48) 47 | 48 | /* MAX size of device secret */ 49 | #define MAX_SIZE_OF_DEVICE_SECRET (64) 50 | 51 | /* MAX size of device cert file name */ 52 | #define MAX_SIZE_OF_DEVICE_CERT_FILE_NAME (128) 53 | 54 | /* MAX size of device key file name */ 55 | #define MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME (128) 56 | 57 | /* MAX size of region len */ 58 | #define MAX_SIZE_OF_REGION (64) 59 | 60 | /* MAX num of subdevice */ 61 | #define MAX_NUM_SUB_DEV (50) 62 | 63 | /**************** QCloud IoT C-SDK constants end *************************/ 64 | typedef enum { 65 | eCOMMON_DEV = 0, // common dev 66 | eGW_DEV = 1, // Gateway dev 67 | eGW_SUB_DEV = 2, // sub dev of Gateway 68 | eDEFAULT_DEV 69 | } eDevType; 70 | 71 | typedef struct { 72 | char product_id[MAX_SIZE_OF_PRODUCT_ID + 1]; 73 | char device_name[MAX_SIZE_OF_DEVICE_NAME + 1]; 74 | char client_id[MAX_SIZE_OF_CLIENT_ID + 1]; 75 | 76 | #ifdef AUTH_MODE_CERT 77 | char dev_cert_file_name[MAX_SIZE_OF_DEVICE_CERT_FILE_NAME + 1]; 78 | char dev_key_file_name[MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME + 1]; 79 | #else 80 | char device_secret[MAX_SIZE_OF_DEVICE_SECRET + 1]; 81 | #endif 82 | 83 | #ifdef DEV_DYN_REG_ENABLED 84 | char product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1]; 85 | #endif 86 | char region[MAX_SIZE_OF_REGION]; 87 | 88 | eDevType dev_type; 89 | } DeviceInfo; 90 | 91 | #ifdef GATEWAY_ENABLED 92 | typedef struct { 93 | DeviceInfo gw_info; 94 | DeviceInfo sub_dev_info[MAX_NUM_SUB_DEV]; 95 | int sub_dev_num; 96 | } GatewayDeviceInfo; 97 | #endif 98 | 99 | #include "qcloud_iot_export_variables.h" 100 | #include "qcloud_iot_export_error.h" 101 | #include "qcloud_iot_export_log.h" 102 | #include "qcloud_iot_export_mqtt.h" 103 | #include "qcloud_iot_export_data_template.h" 104 | #include "qcloud_iot_export_ota.h" 105 | #include "qcloud_iot_export_gateway.h" 106 | #include "qcloud_iot_export_dynreg.h" 107 | #include "qcloud_iot_export_system.h" 108 | 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* QCLOUD_IOT_EXPORT_H_ */ 115 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/qcloud_iot_export_variables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_EXPORT_VARIABLES_H_ 22 | #define QCLOUD_IOT_EXPORT_VARIABLES_H_ 23 | 24 | /* 25 | * Below variables are dependant on user situation (network status/device 26 | * memory/application context) 27 | * Adjust the default value to meet your requirement 28 | */ 29 | 30 | /* default MQTT/CoAP timeout value when connect/pub/sub (unit: ms) */ 31 | #define QCLOUD_IOT_MQTT_COMMAND_TIMEOUT (5 * 1000) 32 | 33 | /* default MQTT keep alive interval (unit: ms) */ 34 | #define QCLOUD_IOT_MQTT_KEEP_ALIVE_INTERNAL (240 * 1000) 35 | 36 | /* default MQTT Tx buffer size, MAX: 16*1024 */ 37 | #define QCLOUD_IOT_MQTT_TX_BUF_LEN (2048) 38 | 39 | /* default MQTT Rx buffer size, MAX: 16*1024 */ 40 | #define QCLOUD_IOT_MQTT_RX_BUF_LEN (2048) 41 | 42 | /* default COAP Tx buffer size, MAX: 1*1024 */ 43 | #define COAP_SENDMSG_MAX_BUFLEN (512) 44 | 45 | /* default COAP Rx buffer size, MAX: 1*1024 */ 46 | #define COAP_RECVMSG_MAX_BUFLEN (512) 47 | 48 | /* MAX MQTT reconnect interval (unit: ms) */ 49 | #define MAX_RECONNECT_WAIT_INTERVAL (60 * 1000) 50 | 51 | /* MAX valid time when connect to MQTT server. 0: always valid */ 52 | /* Use this only if the device has accurate UTC time. Otherwise, set to 0 */ 53 | #define MAX_ACCESS_EXPIRE_TIMEOUT (0) 54 | 55 | /* log print/upload related variables */ 56 | /* MAX size of log buffer for one log item including header and content */ 57 | #define MAX_LOG_MSG_LEN (1023) 58 | 59 | #if defined(__linux__) 60 | #undef MAX_LOG_MSG_LEN 61 | #define MAX_LOG_MSG_LEN (1023) 62 | #endif 63 | 64 | /* 65 | * Log upload related params, which will affect the size of device memory/disk 66 | * consumption 67 | * the default value can be changed for different user situation 68 | */ 69 | // size of buffer for log upload 70 | #define LOG_UPLOAD_BUFFER_SIZE 5000 71 | 72 | // Max size of one http log upload. Should not larger than 5000 73 | #define MAX_HTTP_LOG_POST_SIZE 3000 74 | 75 | // MAX size for saving log into NVS (files/FLASH) after upload fail 76 | #define MAX_LOG_SAVE_SIZE (3 * LOG_UPLOAD_BUFFER_SIZE) 77 | 78 | // interval of log upload (unit: ms) Decrease this value if 79 | // LOG_UPLOAD_BUFFER_SIZE is small 80 | #define LOG_UPLOAD_INTERVAL_MS 2000 81 | 82 | #endif /* QCLOUD_IOT_EXPORT_VARIABLES_H_ */ 83 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/include/utils_getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef __UTILS_GETOPT_H__ 23 | #define __UTILS_GETOPT_H__ 24 | 25 | extern char *utils_optarg; /* pointer to argument of current option */ 26 | int utils_getopt(int nargc, char *const *nargv, const char *options); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/make.settings: -------------------------------------------------------------------------------- 1 | # 编译类型: release/debug 2 | BUILD_TYPE = release 3 | # Makefile编译打印 echo 4 | DEBUG_MAKEFILE = n 5 | 6 | # 编译工具链 7 | PLATFORM_CC = gcc 8 | PLATFORM_AR = ar 9 | PLATFORM_OS = linux 10 | PLATFORM_SSL = mbedtls 11 | PLATFORM_AT_DEV = esp8266 12 | 13 | # 交叉编译工具链示例 14 | # PLATFORM_CC = /opt/openwrt/packages/toolchain/mipsel-linux-gcc 15 | # PLATFORM_AR = /opt/openwrt/packages/toolchain/mipsel-linux-ar 16 | # PLATFORM_CC = armcc 17 | # PLATFORM_AR = armar 18 | 19 | # 是否打开MQTT通道的总开关 20 | FEATURE_MQTT_COMM_ENABLED = y 21 | 22 | # 是否打开网关功能 23 | FEATURE_GATEWAY_ENABLED = n 24 | 25 | # 是否使能多线程 26 | FEATURE_MULTITHREAD_ENABLED = n 27 | 28 | # 是否使能设备动态注册 29 | FEATURE_DEV_DYN_REG_ENABLED = y 30 | 31 | # 是否打开OTA固件升级总开关 32 | FEATURE_OTA_COMM_ENABLED = y 33 | 34 | # 是否使用HTTPS下载固件 35 | FEATURE_OTA_USE_HTTPS = y 36 | 37 | # 接入认证方式,使用证书认证:CERT;使用密钥认证:KEY 38 | FEATURE_AUTH_MODE = KEY 39 | 40 | # 接入认证是否不使用TLS,证书方式必须选择使用TLS,密钥认证可选择不使用TLS 41 | FEATURE_AUTH_WITH_NOTLS = n 42 | 43 | # 是否打开数据模板功能 44 | FEATURE_DATA_TEMPLATE_ENABLED = y 45 | 46 | # 是否打开数据模板事件上报功能 47 | FEATURE_EVENT_POST_ENABLED = n 48 | 49 | # 是否打开数据模板行为功能 50 | FEATURE_ACTION_ENABLED = n 51 | 52 | # 是否打开获取iot后台时间功能 53 | FEATURE_SYSTEM_COMM_ENABLED = n 54 | 55 | # 是否打开日志上报云端功能 56 | FEATURE_LOG_UPLOAD_ENABLED = n 57 | 58 | # 是否打开代码中获取设备信息功能,OFF时将从device_info.json中读取设备信息 59 | FEATURE_DEBUG_DEV_INFO_USED = n 60 | 61 | # 是否使用AT方式实现TCP通信 62 | FEATURE_AT_TCP_ENABLED = n 63 | 64 | # 是否打开AT模组中断接收功能 65 | FEATURE_AT_UART_RECV_IRQ = y 66 | 67 | # 是否打开AT模组多线程功能 68 | FEATURE_AT_OS_USED = y 69 | 70 | # 是否打开AT模组调试功能 71 | FEATURE_AT_DEBUG = y 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/at_device/esp8266/at_device_esp8266.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 __AT_DEVICE_ESP8266_H__ 22 | #define __AT_DEVICE_ESP8266_H__ 23 | 24 | #define AT_RESP_TIMEOUT_MS (5000) 25 | #define ESP8266_SEND_MAX_LEN_ONCE (2048) 26 | #define ESP8266_MAX_SOCKET_NUM (5) 27 | 28 | int at_device_esp8266_init(void); 29 | 30 | #endif /* __AT_DEVICE_ESP8266_H__ */ 31 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/freertos/HAL_AT_UART_freertos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include "qcloud_iot_export.h" 22 | #include "qcloud_iot_import.h" 23 | 24 | #ifdef AT_TCP_ENABLED 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "at_client.h" 32 | #include "stm32l4xx_hal.h" 33 | #include "utils_ringbuff.h" 34 | 35 | #define HAL_AT_UART_IRQHandler USART1_IRQHandler 36 | extern UART_HandleTypeDef huart1; 37 | static UART_HandleTypeDef *pAtUart = &huart1; 38 | 39 | extern void AT_Uart_Init(void); 40 | extern void at_client_uart_rx_isr_cb(uint8_t *pdata, uint8_t len); 41 | 42 | #include "board.h" 43 | /** 44 | * @brief This function handles AT UART global interrupt,push recv char to 45 | * ringbuff. 46 | */ 47 | void HAL_AT_UART_IRQHandler(void) 48 | { 49 | uint8_t ch; 50 | if (__HAL_UART_GET_FLAG(pAtUart, UART_FLAG_RXNE) == SET) { 51 | ch = (uint8_t)READ_REG(pAtUart->Instance->RDR) & 0xFF; 52 | /*this callback for at_client*/ 53 | at_client_uart_rx_isr_cb(&ch, 1); 54 | HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); 55 | } 56 | __HAL_UART_CLEAR_PEFLAG(pAtUart); 57 | } 58 | 59 | /** 60 | *pdata: pointer of data for send 61 | *len: len of data to be sent 62 | *return: the len of data send success 63 | * @brief hal api for at data send 64 | */ 65 | int HAL_AT_Uart_Send(void *data, uint32_t size) 66 | { 67 | if (HAL_OK == HAL_UART_Transmit(pAtUart, data, size, 0xFFFF)) { 68 | return size; 69 | } else { 70 | return 0; 71 | } 72 | } 73 | 74 | int HAL_AT_Uart_Init(void) 75 | { 76 | AT_Uart_Init(); 77 | return QCLOUD_RET_SUCCESS; 78 | } 79 | 80 | int HAL_AT_Uart_Deinit(void) 81 | { 82 | return QCLOUD_RET_SUCCESS; 83 | } 84 | #endif 85 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/freertos/HAL_Timer_freertos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "qcloud_iot_import.h" 32 | 33 | #define PLATFORM_HAS_TIME_FUNCS 34 | //#define PLATFORM_HAS_CMSIS 35 | 36 | #ifdef PLATFORM_HAS_TIME_FUNCS 37 | #include 38 | #include 39 | #endif 40 | 41 | #ifdef PLATFORM_HAS_CMSIS 42 | #include "cmsis_os.h" 43 | #include "stm32l4xx_hal.h" 44 | #endif 45 | 46 | uint32_t HAL_GetTimeMs(void) 47 | { 48 | #if defined PLATFORM_HAS_TIME_FUNCS 49 | struct timeval tv; 50 | gettimeofday(&tv, NULL); 51 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; 52 | 53 | #elif defined PLATFORM_HAS_CMSIS 54 | return HAL_GetTick(); 55 | #endif 56 | } 57 | 58 | /*Get timestamp*/ 59 | long HAL_Timer_current_sec(void) 60 | { 61 | return HAL_GetTimeMs() / 1000; 62 | } 63 | 64 | char *HAL_Timer_current(char *time_str) 65 | { 66 | #if defined PLATFORM_HAS_TIME_FUNCS 67 | struct timeval tv; 68 | gettimeofday(&tv, NULL); 69 | time_t now_time = tv.tv_sec; 70 | struct tm tm_tmp = *localtime(&now_time); 71 | strftime(time_str, TIME_FORMAT_STR_LEN, "%F %T", &tm_tmp); 72 | return time_str; 73 | #else 74 | long time_sec; 75 | time_sec = HAL_Timer_current_sec(); 76 | memset(time_str, 0, TIME_FORMAT_STR_LEN); 77 | snprintf(time_str, TIME_FORMAT_STR_LEN, "%ld", time_sec); 78 | return time_str; 79 | #endif 80 | } 81 | 82 | bool HAL_Timer_expired(Timer *timer) 83 | { 84 | uint32_t now_ts; 85 | 86 | now_ts = HAL_GetTimeMs(); 87 | 88 | return (now_ts > timer->end_time) ? true : false; 89 | } 90 | 91 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 92 | { 93 | timer->end_time = HAL_GetTimeMs(); 94 | timer->end_time += timeout_ms; 95 | } 96 | 97 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 98 | { 99 | timer->end_time = HAL_GetTimeMs(); 100 | timer->end_time += timeout * 1000; 101 | } 102 | 103 | int HAL_Timer_remain(Timer *timer) 104 | { 105 | return (int)(timer->end_time - HAL_GetTimeMs()); 106 | } 107 | 108 | void HAL_Timer_init(Timer *timer) 109 | { 110 | timer->end_time = 0; 111 | } 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/linux/HAL_Log_linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "qcloud_iot_export_error.h" 26 | #include "qcloud_iot_export_log.h" 27 | #include "qcloud_iot_import.h" 28 | 29 | #ifdef LOG_UPLOAD 30 | 31 | #define LOG_SAVE_FILE_PATH "upload-fail-save.log" 32 | 33 | size_t HAL_Log_Save(const char *log, size_t wLen) 34 | { 35 | FILE * fp; 36 | size_t len; 37 | 38 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "a+")) == NULL) { 39 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 40 | return 0; 41 | } 42 | 43 | len = fwrite((void *)log, 1, wLen, fp); 44 | Log_d("write %d of %d to log file", len, wLen); 45 | 46 | fclose(fp); 47 | 48 | return len; 49 | } 50 | 51 | size_t HAL_Log_Read(char *buff, size_t rLen) 52 | { 53 | FILE * fp; 54 | size_t len; 55 | 56 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 57 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 58 | return 0; 59 | } 60 | 61 | len = fread((void *)buff, 1, rLen, fp); 62 | Log_d("read %d of %d from log file", len, rLen); 63 | 64 | fclose(fp); 65 | 66 | return len; 67 | } 68 | 69 | int HAL_Log_Del(void) 70 | { 71 | return remove(LOG_SAVE_FILE_PATH); 72 | } 73 | 74 | size_t HAL_Log_Get_Size(void) 75 | { 76 | long length; 77 | FILE *fp; 78 | 79 | /* check if file exists */ 80 | if (access(LOG_SAVE_FILE_PATH, 0)) 81 | return 0; 82 | 83 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 84 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 85 | return 0; 86 | } 87 | 88 | fseek(fp, 0L, SEEK_END); 89 | length = ftell(fp); 90 | fclose(fp); 91 | if (length > 0) 92 | return (size_t)length; 93 | else 94 | return 0; 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/linux/HAL_Timer_linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | #include "qcloud_iot_import.h" 30 | 31 | bool HAL_Timer_expired(Timer *timer) 32 | { 33 | struct timeval now, res; 34 | gettimeofday(&now, NULL); 35 | timersub(&timer->end_time, &now, &res); 36 | return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); 37 | } 38 | 39 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 40 | { 41 | struct timeval now; 42 | gettimeofday(&now, NULL); 43 | struct timeval interval = {timeout_ms / 1000, (timeout_ms % 1000) * 1000}; 44 | timeradd(&now, &interval, &timer->end_time); 45 | } 46 | 47 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 48 | { 49 | struct timeval now; 50 | gettimeofday(&now, NULL); 51 | struct timeval interval = {timeout, 0}; 52 | timeradd(&now, &interval, &timer->end_time); 53 | } 54 | 55 | int HAL_Timer_remain(Timer *timer) 56 | { 57 | struct timeval now, res; 58 | gettimeofday(&now, NULL); 59 | timersub(&timer->end_time, &now, &res); 60 | return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000; 61 | } 62 | 63 | void HAL_Timer_init(Timer *timer) 64 | { 65 | timer->end_time = (struct timeval){0, 0}; 66 | } 67 | 68 | char *HAL_Timer_current(char *time_str) 69 | { 70 | if (time_str == NULL) 71 | return " "; 72 | 73 | struct timeval tv; 74 | gettimeofday(&tv, NULL); 75 | time_t now_time = tv.tv_sec; 76 | 77 | struct tm tm_tmp = *localtime(&now_time); 78 | strftime(time_str, TIME_FORMAT_STR_LEN, "%F %T", &tm_tmp); 79 | 80 | return time_str; 81 | } 82 | 83 | long HAL_Timer_current_sec(void) 84 | { 85 | struct timeval tv; 86 | gettimeofday(&tv, NULL); 87 | 88 | return tv.tv_sec; 89 | } 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/nonos/HAL_AT_UART_nonos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "at_client.h" 27 | #include "qcloud_iot_export.h" 28 | #include "qcloud_iot_import.h" 29 | #include "stm32l4xx_hal.h" 30 | #include "utils_ringbuff.h" 31 | 32 | #define HAL_AT_UART_IRQHandler USART1_IRQHandler 33 | extern UART_HandleTypeDef huart1; 34 | static UART_HandleTypeDef *pAtUart = &huart1; 35 | 36 | extern void AT_Uart_Init(void); 37 | extern void at_client_uart_rx_isr_cb(uint8_t *pdata, uint8_t len); 38 | 39 | #include "board.h" 40 | /** 41 | * @brief This function handles AT UART global interrupt,push recv char to 42 | * ringbuff. 43 | */ 44 | void HAL_AT_UART_IRQHandler(void) 45 | { 46 | uint8_t ch; 47 | if (__HAL_UART_GET_FLAG(pAtUart, UART_FLAG_RXNE) == SET) { 48 | ch = (uint8_t)READ_REG(pAtUart->Instance->RDR) & 0xFF; 49 | /*this callback for at_client*/ 50 | at_client_uart_rx_isr_cb(&ch, 1); 51 | HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); 52 | } 53 | __HAL_UART_CLEAR_PEFLAG(pAtUart); 54 | } 55 | 56 | /** 57 | *pdata: pointer of data for send 58 | *len: len of data to be sent 59 | *return: the len of data send success 60 | * @brief hal api for at data send 61 | */ 62 | int HAL_AT_Uart_Send(void *data, uint32_t size) 63 | { 64 | if (HAL_OK == HAL_UART_Transmit(pAtUart, data, size, 0xFFFF)) { 65 | return size; 66 | } else { 67 | return 0; 68 | } 69 | } 70 | 71 | int HAL_AT_Uart_Init(void) 72 | { 73 | AT_Uart_Init(); 74 | return QCLOUD_RET_SUCCESS; 75 | } 76 | 77 | int HAL_AT_Uart_Deinit(void) 78 | { 79 | return QCLOUD_RET_SUCCESS; 80 | } 81 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/nonos/HAL_OS_nonos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "qcloud_iot_import.h" 27 | #include "stm32l4xx_hal.h" 28 | 29 | void HAL_Printf(_IN_ const char *fmt, ...) 30 | { 31 | va_list args; 32 | 33 | va_start(args, fmt); 34 | vprintf(fmt, args); 35 | va_end(args); 36 | 37 | fflush(stdout); 38 | } 39 | 40 | int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...) 41 | { 42 | va_list args; 43 | int rc; 44 | 45 | va_start(args, fmt); 46 | rc = vsnprintf(str, len, fmt, args); 47 | va_end(args); 48 | 49 | return rc; 50 | } 51 | 52 | int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap) 53 | { 54 | return vsnprintf(str, len, format, ap); 55 | } 56 | 57 | void HAL_SleepMs(_IN_ uint32_t ms) 58 | { 59 | (void)HAL_Delay(ms); 60 | } 61 | 62 | void HAL_DelayMs(_IN_ uint32_t ms) 63 | { 64 | (void)HAL_Delay(ms); 65 | } 66 | 67 | void HAL_Free(void *ptr) 68 | { 69 | if (ptr) 70 | free(ptr); 71 | } 72 | 73 | void *HAL_Malloc(uint32_t size) 74 | { 75 | return malloc(size); 76 | } 77 | 78 | void *HAL_MutexCreate(void) 79 | { 80 | return (void *)1; 81 | } 82 | 83 | void HAL_MutexDestroy(void *mutex) 84 | { 85 | return; 86 | } 87 | 88 | void HAL_MutexLock(void *mutex) 89 | { 90 | return; 91 | } 92 | 93 | void HAL_MutexUnlock(void *mutex) 94 | { 95 | return; 96 | } 97 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/nonos/HAL_Timer_nonos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "qcloud_iot_import.h" 32 | #include "stm32l4xx_hal.h" 33 | 34 | static char now_time_str[20] = {0}; 35 | 36 | uint32_t HAL_GetTimeMs(void) 37 | { 38 | return HAL_GetTick(); 39 | } 40 | 41 | /*Get timestamp*/ 42 | long HAL_Timer_current_sec(void) 43 | { 44 | // return GetTimeStampByAt(NULL); 45 | 46 | return HAL_GetTimeMs() / 1000; 47 | } 48 | 49 | char *HAL_Timer_current(void) 50 | { 51 | long time_sec; 52 | 53 | time_sec = HAL_Timer_current_sec(); 54 | memset(now_time_str, 0, 20); 55 | snprintf(now_time_str, 20, "%ld", time_sec); 56 | 57 | return now_time_str; 58 | } 59 | 60 | bool HAL_Timer_expired(Timer *timer) 61 | { 62 | uint32_t now_ts; 63 | 64 | now_ts = HAL_GetTimeMs(); 65 | 66 | return (now_ts > timer->end_time) ? true : false; 67 | } 68 | 69 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 70 | { 71 | timer->end_time = HAL_GetTimeMs(); 72 | timer->end_time += timeout_ms; 73 | } 74 | 75 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 76 | { 77 | timer->end_time = HAL_GetTimeMs(); 78 | timer->end_time += timeout * 1000; 79 | } 80 | 81 | int HAL_Timer_remain(Timer *timer) 82 | { 83 | return (int)(timer->end_time - HAL_GetTimeMs()); 84 | } 85 | 86 | void HAL_Timer_init(Timer *timer) 87 | { 88 | timer->end_time = 0; 89 | } 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/rtthread/HAL_OS_rtthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include 22 | #include 23 | #include 24 | 25 | #include "qcloud_iot_export.h" 26 | #include "qcloud_iot_import.h" 27 | #include "rtconfig.h" 28 | 29 | #define HAL_OS_LOG_MAXLEN 1024 30 | static uint16_t g_mutex_count = 0; 31 | 32 | void HAL_Printf(_IN_ const char *fmt, ...) 33 | { 34 | va_list args; 35 | char log_buf[HAL_OS_LOG_MAXLEN]; 36 | 37 | va_start(args, fmt); 38 | rt_vsnprintf(log_buf, HAL_OS_LOG_MAXLEN, fmt, args); 39 | va_end(args); 40 | printf("%s", log_buf); 41 | } 42 | 43 | int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...) 44 | { 45 | va_list args; 46 | int rc; 47 | 48 | va_start(args, fmt); 49 | rc = vsnprintf(str, len, fmt, args); 50 | va_end(args); 51 | 52 | return rc; 53 | } 54 | 55 | int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap) 56 | { 57 | return vsnprintf(str, len, format, ap); 58 | } 59 | 60 | void *HAL_MutexCreate(void) 61 | { 62 | rt_mutex_t mutex; 63 | char mutexName[RT_NAME_MAX]; 64 | 65 | memset(mutexName, 0, RT_NAME_MAX); 66 | HAL_Snprintf(mutexName, RT_NAME_MAX, "tmutex_%d", g_mutex_count++); 67 | mutex = rt_mutex_create(mutexName, RT_IPC_FLAG_FIFO); 68 | if (NULL == mutex) { 69 | HAL_Printf("create mutex failed"); 70 | } 71 | 72 | return mutex; 73 | } 74 | 75 | void HAL_MutexDestroy(_IN_ void *mutex) 76 | { 77 | int err_num; 78 | 79 | err_num = rt_mutex_delete((rt_mutex_t)mutex); 80 | 81 | if (0 != err_num) { 82 | HAL_Printf("destroy mutex failed"); 83 | } 84 | } 85 | 86 | void HAL_MutexLock(_IN_ void *mutex) 87 | { 88 | int err_num; 89 | 90 | err_num = rt_mutex_take((rt_mutex_t)mutex, RT_WAITING_FOREVER); 91 | 92 | if (0 != err_num) { 93 | HAL_Printf("lock mutex failed"); 94 | } 95 | } 96 | 97 | void HAL_MutexUnlock(_IN_ void *mutex) 98 | { 99 | int err_num; 100 | 101 | err_num = rt_mutex_release((rt_mutex_t)mutex); 102 | 103 | if (0 != err_num) { 104 | HAL_Printf("unlock mutex failed"); 105 | } 106 | } 107 | 108 | int HAL_MutexTryLock(_IN_ void *mutex) 109 | { 110 | int err_num; 111 | 112 | err_num = rt_mutex_take((rt_mutex_t)mutex, RT_WAITING_NO); 113 | 114 | if (0 != err_num) { 115 | HAL_Printf("trylock mutex failed"); 116 | } 117 | return err_num; 118 | } 119 | 120 | void *HAL_Malloc(_IN_ uint32_t size) 121 | { 122 | return rt_malloc(size); 123 | } 124 | 125 | void HAL_Free(_IN_ void *ptr) 126 | { 127 | if (ptr) 128 | rt_free(ptr); 129 | } 130 | 131 | void HAL_SleepMs(_IN_ uint32_t ms) 132 | { 133 | (void)rt_thread_delay(rt_tick_from_millisecond(ms)); 134 | } 135 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/rtthread/HAL_Timer_rtthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | #include "qcloud_iot_import.h" 30 | 31 | static char now_time_str[20] = {0}; 32 | 33 | uint32_t HAL_GetTimeMs(void) 34 | { 35 | #if (RT_TICK_PER_SECOND == 1000) 36 | /* #define RT_TICK_PER_SECOND 1000 */ 37 | return (unsigned long)rt_tick_get(); 38 | #else 39 | unsigned long tick = 0; 40 | 41 | tick = rt_tick_get(); 42 | tick = tick * 1000; 43 | return (unsigned long)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND); 44 | #endif 45 | } 46 | 47 | /*Get timestamp*/ 48 | long HAL_Timer_current_sec(void) 49 | { 50 | return HAL_GetTimeMs() / 1000; 51 | } 52 | 53 | char *HAL_Timer_current(void) 54 | { 55 | long time_sec; 56 | 57 | time_sec = HAL_Timer_current_sec(); 58 | memset(now_time_str, 0, 20); 59 | snprintf(now_time_str, 20, "%ld", time_sec); 60 | 61 | return now_time_str; 62 | } 63 | 64 | bool HAL_Timer_expired(Timer *timer) 65 | { 66 | uint32_t now_ts; 67 | 68 | now_ts = HAL_GetTimeMs(); 69 | 70 | return (now_ts > timer->end_time) ? true : false; 71 | } 72 | 73 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 74 | { 75 | timer->end_time = HAL_GetTimeMs(); 76 | timer->end_time += timeout_ms; 77 | } 78 | 79 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 80 | { 81 | timer->end_time = HAL_GetTimeMs(); 82 | timer->end_time += timeout * 1000; 83 | } 84 | 85 | int HAL_Timer_remain(Timer *timer) 86 | { 87 | return (int)(timer->end_time - HAL_GetTimeMs()); 88 | } 89 | 90 | void HAL_Timer_init(Timer *timer) 91 | { 92 | timer->end_time = 0; 93 | } 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/windows/HAL_AT_UART_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "qcloud_iot_export.h" 23 | #include "qcloud_iot_import.h" 24 | 25 | #ifdef AT_TCP_ENABLED 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "at_client.h" 33 | #include "utils_ringbuff.h" 34 | 35 | /** 36 | * @brief This function handles AT UART global interrupt,push recv char to 37 | * ringbuff. 38 | */ 39 | void HAL_AT_UART_IRQHandler(void) {} 40 | 41 | /** 42 | *pdata: pointer of data for send 43 | *len: len of data to be sent 44 | *return: the len of data send success 45 | * @brief hal api for at data send 46 | */ 47 | int HAL_AT_Uart_Send(void *data, uint32_t size) 48 | { 49 | return 0; 50 | } 51 | 52 | int HAL_AT_Uart_Init(void) 53 | { 54 | return QCLOUD_RET_SUCCESS; 55 | } 56 | 57 | int HAL_AT_Uart_Deinit(void) 58 | { 59 | return QCLOUD_RET_SUCCESS; 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/windows/HAL_Log_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "qcloud_iot_export_error.h" 26 | #include "qcloud_iot_export_log.h" 27 | #include "qcloud_iot_import.h" 28 | 29 | #ifdef LOG_UPLOAD 30 | 31 | #define LOG_SAVE_FILE_PATH "upload-fail-save.log" 32 | 33 | size_t HAL_Log_Save(const char *log, size_t wLen) 34 | { 35 | FILE * fp; 36 | size_t len; 37 | 38 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "a+")) == NULL) { 39 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 40 | return 0; 41 | } 42 | 43 | len = fwrite((void *)log, 1, wLen, fp); 44 | Log_d("write %d of %d to log file", len, wLen); 45 | 46 | fclose(fp); 47 | 48 | return len; 49 | } 50 | 51 | size_t HAL_Log_Read(char *buff, size_t rLen) 52 | { 53 | FILE * fp; 54 | size_t len; 55 | 56 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 57 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 58 | return 0; 59 | } 60 | 61 | len = fread((void *)buff, 1, rLen, fp); 62 | Log_d("read %d of %d from log file", len, rLen); 63 | 64 | fclose(fp); 65 | 66 | return len; 67 | } 68 | 69 | int HAL_Log_Del(void) 70 | { 71 | return remove(LOG_SAVE_FILE_PATH); 72 | } 73 | 74 | size_t HAL_Log_Get_Size(void) 75 | { 76 | long length; 77 | FILE *fp; 78 | 79 | /* check if file exists */ 80 | if (access(LOG_SAVE_FILE_PATH, 0)) 81 | return 0; 82 | 83 | if ((fp = fopen(LOG_SAVE_FILE_PATH, "r")) == NULL) { 84 | Log_e("fail to open file %s", LOG_SAVE_FILE_PATH); 85 | return 0; 86 | } 87 | 88 | fseek(fp, 0L, SEEK_END); 89 | length = ftell(fp); 90 | fclose(fp); 91 | if (length > 0) 92 | return (size_t)length; 93 | else 94 | return 0; 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/platform/os/windows/HAL_Timer_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | #include "qcloud_iot_import.h" 30 | 31 | bool HAL_Timer_expired(Timer *timer) 32 | { 33 | if (GetTickCount64() >= timer->end_time) { 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | 40 | void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) 41 | { 42 | timer->end_time = GetTickCount64() + timeout_ms; 43 | } 44 | 45 | void HAL_Timer_countdown(Timer *timer, unsigned int timeout) 46 | { 47 | timer->end_time = GetTickCount64() + (UINT64)timeout * 1000; 48 | } 49 | 50 | int HAL_Timer_remain(Timer *timer) 51 | { 52 | UINT64 now = GetTickCount64(); 53 | 54 | if (now >= timer->end_time) { 55 | return 0; 56 | } 57 | 58 | return (int)(timer->end_time - now); 59 | } 60 | 61 | void HAL_Timer_init(Timer *timer) 62 | { 63 | timer->end_time = 0; 64 | } 65 | 66 | char *HAL_Timer_current(char *time_str) 67 | { 68 | time_t now; 69 | struct tm tm_val; 70 | 71 | time(&now); 72 | localtime_s(&tm_val, &now); 73 | 74 | snprintf(time_str, TIME_FORMAT_STR_LEN, "%04d/%02d/%02d %02d:%02d:%02d", tm_val.tm_year + 1900, tm_val.tm_mon + 1, 75 | tm_val.tm_mday, tm_val.tm_hour, tm_val.tm_min, tm_val.tm_sec); 76 | 77 | return time_str; 78 | } 79 | 80 | long HAL_Timer_current_sec(void) 81 | { 82 | return (long)(GetTickCount64() / 1000); 83 | } 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(INC_DIR ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/include) 3 | set(LINK_DIR ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/lib/) 4 | include_directories(${INC_DIR}) 5 | link_directories(${LINK_DIR}) 6 | 7 | if(FEATURE_AUTH_WITH_NOTLS) 8 | set(link_lib 9 | iot_sdk 10 | iot_platform 11 | ) 12 | else() 13 | set(link_lib 14 | iot_sdk 15 | iot_platform 16 | mbedtls 17 | mbedx509 18 | mbedcrypto 19 | ) 20 | endif() 21 | 22 | if(CMAKE_COMPILER_IS_GNUCC) 23 | set(lib -Wl,--start-group ${link_lib} -Wl,--end-group) 24 | else() 25 | set(lib ${link_lib}) 26 | endif() 27 | 28 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/bin) 29 | 30 | 31 | # data_template 32 | file(GLOB src_data_template_sample ${PROJECT_SOURCE_DIR}/samples/data_template/data_template_sample.c) 33 | add_executable(data_template_sample ${src_data_template_sample}) 34 | target_link_libraries(data_template_sample ${lib}) 35 | 36 | file(GLOB src_light_data_template_sample ${PROJECT_SOURCE_DIR}/samples/scenarized/light_data_template_sample.c) 37 | add_executable(light_data_template_sample ${src_light_data_template_sample}) 38 | target_link_libraries(light_data_template_sample ${lib}) 39 | 40 | # MQTT 41 | file(GLOB src_mqtt_sample ${PROJECT_SOURCE_DIR}/samples/mqtt/mqtt_sample.c) 42 | add_executable(mqtt_sample ${src_mqtt_sample}) 43 | target_link_libraries(mqtt_sample ${lib}) 44 | 45 | # Raw data 46 | file(GLOB src_raw_data ${PROJECT_SOURCE_DIR}/samples/raw_data/raw_data_sample.c) 47 | add_executable(raw_data_mqtt_sample ${src_raw_data}) 48 | target_link_libraries(raw_data_mqtt_sample ${lib}) 49 | 50 | # GATEWAY 51 | if(${FEATURE_GATEWAY_ENABLED} STREQUAL "ON") 52 | file(GLOB src_gateway_sample ${PROJECT_SOURCE_DIR}/samples/gateway/*.c) 53 | add_executable(gateway_sample ${src_gateway_sample}) 54 | target_link_libraries(gateway_sample ${lib}) 55 | endif() 56 | 57 | # OTA MQTT 58 | if(${FEATURE_OTA_COMM_ENABLED} STREQUAL "ON") 59 | file(GLOB src_ota_mqtt_sample ${PROJECT_SOURCE_DIR}/samples/ota/ota_mqtt_sample.c) 60 | add_executable(ota_mqtt_sample ${src_ota_mqtt_sample}) 61 | target_link_libraries(ota_mqtt_sample ${lib}) 62 | endif() 63 | 64 | # DYN_REG 65 | if(${FEATURE_DEV_DYN_REG_ENABLED} STREQUAL "ON") 66 | file(GLOB src_dynreg_dev_sample ${PROJECT_SOURCE_DIR}/samples/dynreg_dev/dynreg_dev_sample.c) 67 | add_executable(dynreg_dev_sample ${src_dynreg_dev_sample}) 68 | target_link_libraries(dynreg_dev_sample ${lib}) 69 | endif() 70 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/samples/Makefile: -------------------------------------------------------------------------------- 1 | # Basic Settings 2 | SHELL := /bin/bash 3 | TOP_DIR ?= $(CURDIR)/../ 4 | SUBDIRS := directory-not-exist-actually 5 | 6 | # Settings of input directory 7 | SCRIPT_DIR := $(TOP_DIR)/tools/build_scripts 8 | 9 | include $(TOP_DIR)/make.settings 10 | include $(SCRIPT_DIR)/parse_make_settings.mk 11 | 12 | # Makefile echo 13 | ifeq ($(DEBUG_MAKEFILE),n) 14 | Q := @ 15 | TOP_Q := @ 16 | else 17 | Q := 18 | TOP_Q := 19 | endif 20 | 21 | # Settings of output directory 22 | SAMPLE_DIR := $(CURDIR) 23 | FINAL_DIR := $(CURDIR)/../output/$(BUILD_TYPE) 24 | 25 | IOT_LIB_DIR = $(FINAL_DIR)/lib 26 | IOT_INC_CFLAGS = -I$(FINAL_DIR)/include -I$(FINAL_DIR)/include/exports -I$(CURDIR)/../sdk_src/internal_inc 27 | 28 | LDFLAGS := -Wl,--start-group $(IOT_LIB_DIR)/libiot_sdk.a 29 | ifeq ($(FEATURE_AUTH_WITH_NOTLS),n) 30 | LDFLAGS += $(IOT_LIB_DIR)/libmbedtls.a $(IOT_LIB_DIR)/libmbedx509.a $(IOT_LIB_DIR)/libmbedcrypto.a 31 | endif 32 | LDFLAGS += $(IOT_LIB_DIR)/libiot_platform.a -Wl,--end-group 33 | 34 | 35 | CFLAGS += -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread -DFORCE_SSL_VERIFY 36 | CFLAGS += ${IOT_INC_CFLAGS} 37 | 38 | ifeq ($(FEATURE_AUTH_MODE),CERT) 39 | CFLAGS += -DAUTH_MODE_CERT 40 | endif 41 | 42 | .PHONY: ota_mqtt_sample data_template_sample gateway_sample mqtt_sample dynreg_dev_sample 43 | 44 | all: ota_mqtt_sample data_template_sample gateway_sample mqtt_sample dynreg_dev_sample 45 | 46 | 47 | ifneq (,$(filter -DOTA_COMM_ENABLED,$(CFLAGS))) 48 | ota_mqtt_sample: 49 | $(TOP_Q) \ 50 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/ota/$@.c $(LDFLAGS) -o $@ 51 | 52 | $(TOP_Q) \ 53 | mv $@ $(FINAL_DIR)/bin 54 | endif 55 | 56 | ifneq (,$(filter -DDATA_TEMPLATE_ENABLED,$(CFLAGS))) 57 | data_template_sample: 58 | $(TOP_Q) \ 59 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/data_template/$@.c $(LDFLAGS) -o $@ 60 | 61 | $(TOP_Q) \ 62 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/scenarized/light_$@.c $(LDFLAGS) -o light_$@ 63 | 64 | $(TOP_Q) \ 65 | mv $@ $(FINAL_DIR)/bin && \ 66 | mv light_$@ $(FINAL_DIR)/bin 67 | endif 68 | 69 | ifneq (,$(filter -DMQTT_COMM_ENABLED,$(CFLAGS))) 70 | mqtt_sample: 71 | $(TOP_Q) \ 72 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/mqtt/$@.c $(LDFLAGS) -o $@ 73 | 74 | $(TOP_Q) \ 75 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/raw_data/*.c $(LDFLAGS) -o raw_data_$@ 76 | 77 | $(TOP_Q) \ 78 | mv raw_data_$@ $(FINAL_DIR)/bin && \ 79 | mv $@ $(FINAL_DIR)/bin 80 | endif 81 | 82 | ifneq (,$(filter -DGATEWAY_ENABLED,$(CFLAGS))) 83 | gateway_sample: 84 | $(TOP_Q) \ 85 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/gateway/*.c $(LDFLAGS) -o $@ 86 | 87 | $(TOP_Q) \ 88 | mv $@ $(FINAL_DIR)/bin 89 | endif 90 | 91 | ifneq (,$(filter -DDEV_DYN_REG_ENABLED,$(CFLAGS))) 92 | dynreg_dev_sample: 93 | $(TOP_Q) \ 94 | $(PLATFORM_CC) $(CFLAGS) $(SAMPLE_DIR)/dynreg_dev/$@.c $(LDFLAGS) -o $@ 95 | 96 | $(TOP_Q) \ 97 | mv $@ $(FINAL_DIR)/bin 98 | endif 99 | 100 | clean: 101 | rm -rf $(FINAL_DIR)/bin/* 102 | 103 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/samples/data_template/action_config.c: -------------------------------------------------------------------------------- 1 | #ifdef ACTION_ENABLED 2 | 3 | #define TOTAL_ACTION_COUNTS (1) 4 | 5 | static TYPE_DEF_TEMPLATE_INT sg_light_blink_in_time = 0; 6 | static TYPE_DEF_TEMPLATE_BOOL sg_light_blink_in_color = 0; 7 | static TYPE_DEF_TEMPLATE_INT sg_light_blink_in_total_time = 0; 8 | static DeviceProperty g_actionInput_light_blink[] = { 9 | 10 | {.key = "time", .data = &sg_light_blink_in_time, .type = TYPE_TEMPLATE_INT}, 11 | {.key = "color", .data = &sg_light_blink_in_color, .type = TYPE_TEMPLATE_BOOL}, 12 | {.key = "total_time", .data = &sg_light_blink_in_total_time, .type = TYPE_TEMPLATE_INT}, 13 | }; 14 | static TYPE_DEF_TEMPLATE_BOOL sg_light_blink_out_err_code = 0; 15 | static DeviceProperty g_actionOutput_light_blink[] = { 16 | 17 | {.key = "err_code", .data = &sg_light_blink_out_err_code, .type = TYPE_TEMPLATE_BOOL}, 18 | }; 19 | 20 | static DeviceAction g_actions[] = { 21 | 22 | { 23 | .pActionId = "light_blink", 24 | .timestamp = 0, 25 | .input_num = sizeof(g_actionInput_light_blink) / sizeof(g_actionInput_light_blink[0]), 26 | .output_num = sizeof(g_actionOutput_light_blink) / sizeof(g_actionOutput_light_blink[0]), 27 | .pInput = g_actionInput_light_blink, 28 | .pOutput = g_actionOutput_light_blink, 29 | }, 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/samples/data_template/data_config.c: -------------------------------------------------------------------------------- 1 | /*-----------------data config start -------------------*/ 2 | 3 | #define TOTAL_PROPERTY_COUNT 4 4 | 5 | static sDataPoint sg_DataTemplate[TOTAL_PROPERTY_COUNT]; 6 | 7 | typedef struct _ProductDataDefine { 8 | TYPE_DEF_TEMPLATE_BOOL m_power_switch; 9 | TYPE_DEF_TEMPLATE_ENUM m_color; 10 | TYPE_DEF_TEMPLATE_INT m_brightness; 11 | TYPE_DEF_TEMPLATE_STRING m_name[64 + 1]; 12 | } ProductDataDefine; 13 | 14 | static ProductDataDefine sg_ProductData; 15 | 16 | static void _init_data_template(void) 17 | { 18 | sg_ProductData.m_power_switch = 0; 19 | sg_DataTemplate[0].data_property.data = &sg_ProductData.m_power_switch; 20 | sg_DataTemplate[0].data_property.key = "power_switch"; 21 | sg_DataTemplate[0].data_property.type = TYPE_TEMPLATE_BOOL; 22 | 23 | sg_ProductData.m_color = 0; 24 | sg_DataTemplate[1].data_property.data = &sg_ProductData.m_color; 25 | sg_DataTemplate[1].data_property.key = "color"; 26 | sg_DataTemplate[1].data_property.type = TYPE_TEMPLATE_ENUM; 27 | 28 | sg_ProductData.m_brightness = 1; 29 | sg_DataTemplate[2].data_property.data = &sg_ProductData.m_brightness; 30 | sg_DataTemplate[2].data_property.key = "brightness"; 31 | sg_DataTemplate[2].data_property.type = TYPE_TEMPLATE_INT; 32 | 33 | sg_ProductData.m_name[0] = '\0'; 34 | sg_DataTemplate[3].data_property.data = sg_ProductData.m_name; 35 | sg_DataTemplate[3].data_property.data_buff_len = sizeof(sg_ProductData.m_name) / sizeof(sg_ProductData.m_name[3]); 36 | sg_DataTemplate[3].data_property.key = "name"; 37 | sg_DataTemplate[3].data_property.type = TYPE_TEMPLATE_STRING; 38 | }; 39 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/samples/data_template/events_config.c: -------------------------------------------------------------------------------- 1 | #ifdef EVENT_POST_ENABLED 2 | 3 | #define EVENT_COUNTS (3) 4 | 5 | static TYPE_DEF_TEMPLATE_BOOL sg_status_report_status = 0; 6 | static TYPE_DEF_TEMPLATE_STRING sg_status_report_message[64 + 1] = {0}; 7 | static DeviceProperty g_propertyEvent_status_report[] = { 8 | 9 | {.key = "status", .data = &sg_status_report_status, .type = TYPE_TEMPLATE_BOOL}, 10 | {.key = "message", .data = sg_status_report_message, .type = TYPE_TEMPLATE_STRING}, 11 | }; 12 | 13 | static TYPE_DEF_TEMPLATE_FLOAT sg_low_voltage_voltage = 1; 14 | static DeviceProperty g_propertyEvent_low_voltage[] = { 15 | 16 | {.key = "voltage", .data = &sg_low_voltage_voltage, .type = TYPE_TEMPLATE_FLOAT}, 17 | }; 18 | 19 | static TYPE_DEF_TEMPLATE_STRING sg_hardware_fault_name[64 + 1] = {0}; 20 | static TYPE_DEF_TEMPLATE_INT sg_hardware_fault_error_code = 1; 21 | static DeviceProperty g_propertyEvent_hardware_fault[] = { 22 | 23 | {.key = "name", .data = sg_hardware_fault_name, .type = TYPE_TEMPLATE_STRING}, 24 | {.key = "error_code", .data = &sg_hardware_fault_error_code, .type = TYPE_TEMPLATE_INT}, 25 | }; 26 | 27 | static sEvent g_events[] = { 28 | 29 | { 30 | .event_name = "status_report", 31 | .type = "info", 32 | .timestamp = 0, 33 | .eventDataNum = sizeof(g_propertyEvent_status_report) / sizeof(g_propertyEvent_status_report[0]), 34 | .pEventData = g_propertyEvent_status_report, 35 | }, 36 | { 37 | .event_name = "low_voltage", 38 | .type = "alert", 39 | .timestamp = 0, 40 | .eventDataNum = sizeof(g_propertyEvent_low_voltage) / sizeof(g_propertyEvent_low_voltage[0]), 41 | .pEventData = g_propertyEvent_low_voltage, 42 | }, 43 | { 44 | .event_name = "hardware_fault", 45 | .type = "fault", 46 | .timestamp = 0, 47 | .eventDataNum = sizeof(g_propertyEvent_hardware_fault) / sizeof(g_propertyEvent_hardware_fault[0]), 48 | .pEventData = g_propertyEvent_hardware_fault, 49 | }, 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # UTILS 3 | file(GLOB src_utils ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.c) 4 | set(src_sdk ${src_utils}) 5 | 6 | # data_template 7 | file(GLOB src_mqtt ${CMAKE_CURRENT_SOURCE_DIR}/protocol/mqtt/*.c) 8 | list(APPEND src_sdk ${src_mqtt}) 9 | 10 | file(GLOB src_data_template ${CMAKE_CURRENT_SOURCE_DIR}/services/data_template/*.c) 11 | list(APPEND src_sdk ${src_data_template}) 12 | 13 | # gateway 14 | if(${FEATURE_GATEWAY_ENABLED} STREQUAL "ON") 15 | file(GLOB src_gateway ${CMAKE_CURRENT_SOURCE_DIR}/services/gateway/*.c) 16 | list(APPEND src_sdk ${src_gateway}) 17 | endif() 18 | 19 | # ota mqtt 20 | if(${FEATURE_OTA_COMM_ENABLED} STREQUAL "ON") 21 | file(GLOB src_mqtt_ota 22 | ${CMAKE_CURRENT_SOURCE_DIR}/services/ota/ota_client.c 23 | ${CMAKE_CURRENT_SOURCE_DIR}/services/ota/ota_fetch.c 24 | ${CMAKE_CURRENT_SOURCE_DIR}/services/ota/ota_lib.c 25 | ${CMAKE_CURRENT_SOURCE_DIR}/services/ota/ota_mqtt.c) 26 | list(APPEND src_sdk ${src_mqtt_ota}) 27 | endif() 28 | 29 | 30 | # HTTP 31 | if(${FEATURE_OTA_COMM_ENABLED} STREQUAL "ON" OR ${FEATURE_DEV_DYN_REG_ENABLED} STREQUAL "ON" OR ${FEATURE_LOG_UPLOAD_ENABLED} STREQUAL "ON") 32 | # http 33 | file(GLOB src_http ${CMAKE_CURRENT_SOURCE_DIR}/protocol/http/*.c) 34 | list(APPEND src_sdk ${src_http}) 35 | endif() 36 | 37 | # DYN REG 38 | if(${FEATURE_DEV_DYN_REG_ENABLED} STREQUAL "ON") 39 | file(GLOB src_dyn_reg ${CMAKE_CURRENT_SOURCE_DIR}/services/dynreg/*.c) 40 | list(APPEND src_sdk ${src_dyn_reg}) 41 | endif() 42 | 43 | # LOG 44 | if(${FEATURE_LOG_UPLOAD_ENABLED} STREQUAL "ON") 45 | file(GLOB src_log_upload ${CMAKE_CURRENT_SOURCE_DIR}/services/log/*.c) 46 | list(APPEND src_sdk ${src_log_upload}) 47 | endif() 48 | 49 | #SYSTEM RESOURCE 50 | if(${FEATURE_SYSTEM_COMM_ENABLED} STREQUAL "ON") 51 | file(GLOB src_system ${CMAKE_CURRENT_SOURCE_DIR}/services/system/*.c) 52 | list(APPEND src_sdk ${src_system}) 53 | endif() 54 | 55 | # AT OR TCP 56 | if(${FEATURE_AT_TCP_ENABLED} STREQUAL "ON") 57 | # at 58 | file(GLOB src_at_socket ${CMAKE_CURRENT_SOURCE_DIR}/network/at_socket/*.c) 59 | list(APPEND src_sdk ${src_at_socket}) 60 | endif() 61 | 62 | # TLS 63 | if(${FEATURE_AUTH_WITH_NOTLS} STREQUAL "OFF") 64 | file(GLOB src_tls ${CMAKE_CURRENT_SOURCE_DIR}/network/tls/*.c) 65 | list(APPEND src_sdk ${src_tls}) 66 | endif() 67 | 68 | # NETWORK 69 | # tcp 70 | file(GLOB src_socket ${CMAKE_CURRENT_SOURCE_DIR}/network/socket/*.c) 71 | list(APPEND src_sdk ${src_socket}) 72 | # interface 73 | file(GLOB src_network ${CMAKE_CURRENT_SOURCE_DIR}/network/*.c) 74 | list(APPEND src_sdk ${src_network}) 75 | 76 | 77 | # code output 78 | if(${EXTRACT_SRC} STREQUAL "ON") 79 | file(COPY ${src_sdk} DESTINATION ${PROJECT_SOURCE_DIR}/output/qcloud_iot_c_sdk/sdk_src/) 80 | endif() 81 | set(service_target "iot_sdk") 82 | SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/lib/) 83 | add_library(${service_target} STATIC ${src_sdk}) 84 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/at_socket_inf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Tencent Group. All rights reserved. 3 | * License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | * not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | #ifndef _AT_SOCKET_INF_H_ 20 | #define _AT_SOCKET_INF_H_ 21 | 22 | #include 23 | #include 24 | 25 | #include "utils_list.h" 26 | 27 | #define UNUSED_SOCKET (-1) 28 | #define MAX_AT_SOCKET_NUM (5) 29 | #define AT_SOCKET_SEND_TIMEOUT_MS (1000) 30 | #define AT_SOCKET_RECV_TIMEOUT_MS (1000) 31 | #define IPV4_STR_MAX_LEN (16) 32 | 33 | typedef enum { eNET_TCP = 6, eNET_UDP = 17, eNET_DEFAULT = 0xff } eNetProto; 34 | 35 | typedef enum { eSOCKET_ALLOCED = 0, eSOCKET_CONNECTED, eSOCKET_CLOSED } eSocketState; 36 | 37 | /* AT receive package list structure */ 38 | typedef struct at_recv_pkt { 39 | List list; 40 | size_t bfsz_totle; 41 | size_t bfsz_index; 42 | char * buff; 43 | } at_recv_pkt; 44 | 45 | typedef enum { 46 | AT_SOCKET_EVT_RECV = 0, 47 | AT_SOCKET_EVT_CLOSED, 48 | } at_socket_evt_t; 49 | 50 | typedef void (*at_evt_cb_t)(int fd, at_socket_evt_t event, char *buff, size_t bfsz); 51 | 52 | /*at device driver ops, use at_device_op_register register to at socket*/ 53 | typedef struct { 54 | int (*init)(void); 55 | int (*get_local_mac)(char *macbuff, size_t bufflen); 56 | int (*get_local_ip)(char *ip, size_t iplen, char *gw, size_t gwlen, char *mask, size_t masklen); 57 | int (*parse_domain)(const char *host_name, char *host_ip, size_t host_ip_len); 58 | int (*connect)(const char *ip, uint16_t port, eNetProto proto); 59 | int (*send)(int fd, const void *buf, size_t len); 60 | int (*recv_timeout)(int fd, void *buf, size_t len, uint32_t timeout); 61 | int (*close)(int fd); 62 | void (*set_event_cb)(at_socket_evt_t event, at_evt_cb_t cb); 63 | char *deviceName; 64 | } at_device_op_t; 65 | 66 | /*at socket context*/ 67 | typedef struct { 68 | int fd; /** socket fd */ 69 | List * recvpkt_list; 70 | char remote_ip[IPV4_STR_MAX_LEN]; 71 | uint16_t remote_port; 72 | uint32_t send_timeout_ms; 73 | uint32_t recv_timeout_ms; 74 | void * recv_lock; 75 | at_device_op_t *dev_op; 76 | eNetProto net_type; 77 | eSocketState state; 78 | } at_socket_ctx_t; 79 | 80 | // at socket api 81 | int at_device_op_register(at_device_op_t *device_op); 82 | int at_socket_init(void); 83 | int at_socket_parse_domain(const char *host_name, char *host_ip, size_t host_ip_len); 84 | int at_socket_get_local_mac(char *macbuff, size_t bufflen); 85 | int at_socket_get_local_ip(char *ip, size_t iplen, char *gw, size_t gwlen, char *mask, size_t masklen); 86 | int at_socket_connect(const char *host, uint16_t port, eNetProto eProto); 87 | int at_socket_close(int fd); 88 | int at_socket_send(int fd, const void *buf, size_t len); 89 | int at_socket_recv(int fd, void *buf, size_t len); 90 | #endif 91 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/at_uart_hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 __AT_UART_HAL_H__ 22 | #define __AT_UART_HAL_H__ 23 | 24 | /* 25 | * UART data width 26 | */ 27 | typedef enum { 28 | BAUDRATE_2400 = 2400, 29 | BAUDRATE_4800 = 4800, 30 | BAUDRATE_9600 = 9600, 31 | BAUDRATE_19200 = 19200, 32 | BAUDRATE_115200 = 115200, 33 | BAUDRATE_921600 = 921600, 34 | BAUDRATE_DEFAULT = 115200 35 | } hal_uart_baudr_t; 36 | 37 | /* 38 | * UART data width 39 | */ 40 | typedef enum { 41 | DATA_WIDTH_5BIT, 42 | DATA_WIDTH_6BIT, 43 | DATA_WIDTH_7BIT, 44 | DATA_WIDTH_8BIT, 45 | DATA_WIDTH_9BIT 46 | } hal_uart_data_width_t; 47 | 48 | /* 49 | * UART stop bits 50 | */ 51 | typedef enum { STOP_BITS_1, STOP_BITS_2 } hal_uart_stop_bits_t; 52 | 53 | /* 54 | * UART flow control 55 | */ 56 | typedef enum { 57 | FLOW_CONTROL_DISABLED, 58 | FLOW_CONTROL_CTS, 59 | FLOW_CONTROL_RTS, 60 | FLOW_CONTROL_CTS_RTS 61 | } hal_uart_flow_control_t; 62 | 63 | /* 64 | * UART parity 65 | */ 66 | typedef enum { NO_PARITY, ODD_PARITY, EVEN_PARITY } hal_uart_parity_t; 67 | 68 | /* 69 | * UART mode 70 | */ 71 | typedef enum { MODE_TX, MODE_RX, MODE_TX_RX } hal_uart_mode_t; 72 | 73 | /* 74 | * UART state 75 | */ 76 | typedef enum { 77 | eUNUSED = 0, 78 | eOPENED = 1, 79 | eCLOSED = 2, 80 | } hal_uart_state_t; 81 | 82 | /* 83 | * UART configuration 84 | */ 85 | typedef struct { 86 | uint32_t baud_rate; 87 | hal_uart_data_width_t data_width; 88 | hal_uart_parity_t parity; 89 | hal_uart_stop_bits_t stop_bits; 90 | hal_uart_flow_control_t flow_control; 91 | hal_uart_mode_t mode; 92 | } uart_config_t; 93 | 94 | typedef struct { 95 | #ifdef __linux__ 96 | int fd; /* uart fd */ 97 | #else 98 | void *uart_handle; /* uart handle,like stm32 UART_HandleTypeDef */ 99 | #endif 100 | hal_uart_state_t state; /* uart state */ 101 | uart_config_t config; /* uart config */ 102 | } uart_dev_t; 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* __AT_H__ */ 109 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/at_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Tencent Group. All rights reserved. 3 | * License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | * not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | #ifndef _AT_UTILS_H_ 20 | #define _AT_UTILS_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #define WIDTH_SIZE 32 27 | 28 | #ifndef __INT_MAX__ 29 | #define __INT_MAX__ 2147483647 30 | #endif 31 | 32 | #ifndef INT_MAX 33 | #define INT_MAX (__INT_MAX__) 34 | #endif 35 | 36 | #define AT_CMD_COMMA_MARK ',' 37 | #define AT_CMD_DQUOTES_MARK '"' 38 | 39 | #define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ') 40 | 41 | int at_vprintfln(const char *format, va_list args); 42 | void at_print_raw_cmd(const char *name, const char *cmd, int size); 43 | const char *at_get_last_cmd(int *cmd_size); 44 | int at_req_parse_args(const char *req_args, const char *req_expr, ...); 45 | int at_sscanf(const char *buf, const char *fmt, va_list args); 46 | void at_strip(char *str, const char patten); 47 | void chr_strip(char *str, const char patten); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/data_template_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 _DATA_TEMPLATE_ACTION_H_ 22 | #define _DATA_TEMPLATE_ACTION_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define ACTION_NAME_MAX_LEN (20) // action name max len 34 | #define ACTION_TOKEN_MAX_LEN (32) // action token max len 35 | 36 | #define MAX_ACTION_WAIT_REPLY (10) 37 | #define ACTION_MAX_DATA_NUM (255) // input or output max data num 38 | 39 | #define REPORT_ACTION "action_reply" 40 | #define CALL_ACTION "action" 41 | 42 | int IOT_Action_Init(void *c); 43 | 44 | int IOT_Action_Register(void *pTemplate, DeviceAction *pAction, OnActionHandleCallback callback); 45 | 46 | int IOT_Action_Remove(void *ptemplate, DeviceAction *pAction); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif //_DATA_TEMPLATE_ACTION_H_ 53 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/data_template_client_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_DATA_TEMPLATE_CLIENT_COMMON_H_ 22 | #define IOT_DATA_TEMPLATE_CLIENT_COMMON_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "data_template_client.h" 29 | 30 | /** 31 | * @brief register a device property 32 | * 33 | * @param pTemplate handle to data_template client 34 | * @param pProperty device property 35 | * @param callback callback when property changes 36 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 37 | */ 38 | 39 | int template_common_register_property_on_delta(Qcloud_IoT_Template *pTemplate, DeviceProperty *pProperty, 40 | OnPropRegCallback callback); 41 | 42 | /** 43 | * @brief remove a device property 44 | * 45 | * @param pTemplate handle to data_template client 46 | * @param pProperty device property 47 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 48 | */ 49 | int template_common_remove_property(Qcloud_IoT_Template *ptemplate, DeviceProperty *pProperty); 50 | 51 | /** 52 | * @brief check if a device property exists 53 | * 54 | * @param pShadow handle to data_template client 55 | * @param pProperty device property 56 | * @return 0 = not existed 57 | */ 58 | int template_common_check_property_existence(Qcloud_IoT_Template *ptemplate, DeviceProperty *pProperty); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif // IOT_DATA_TEMPLATE_CLIENT_COMMON_H_ 65 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/data_template_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 _DATA_TEMPLATE_EVENT_H_ 22 | #define _DATA_TEMPLATE_EVENT_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define NAME_MAX_LEN (32) 34 | #define TYPE_MAX_LEN (32) 35 | #define EVENT_TOKEN_MAX_LEN (32) 36 | #define SIGLE_EVENT (1) 37 | #define MUTLTI_EVENTS (2) 38 | 39 | #define MAX_EVENT_WAIT_REPLY (10) 40 | #define EVENT_MAX_DATA_NUM (255) 41 | 42 | #define POST_EVENT "event_post" 43 | #define POST_EVENTS "events_post" 44 | #define REPLY_EVENT "event_reply" 45 | 46 | /** 47 | * @brief event's method, post and reply 48 | */ 49 | typedef enum { 50 | eEVENT_POST, 51 | eEVENT_REPLY, 52 | } eEventMethod; 53 | 54 | typedef enum _eEventDealType_ { 55 | eDEAL_REPLY_CB = 0, 56 | eDEAL_EXPIRED = 1, 57 | } eEventDealType; 58 | 59 | typedef struct _sReply_ { 60 | char client_token[EVENT_TOKEN_MAX_LEN]; // clientToken for this event reply 61 | void *user_context; // user context 62 | Timer timer; // timer for request timeout 63 | 64 | OnEventReplyCallback callback; // callback for this event reply 65 | } sEventReply; 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | #endif //_DATA_TEMPLATE_EVENT_H_ -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/log_upload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_LOG_UPLOAD_H_ 22 | #define QCLOUD_IOT_LOG_UPLOAD_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "qcloud_iot_export_log.h" 29 | 30 | /** 31 | * @brief init the log upload functions 32 | * 33 | * @param init_params 34 | * @return QCLOUD_RET_SUCCESS when success 35 | */ 36 | int init_log_uploader(LogUploadInitParams *init_params); 37 | 38 | /** 39 | * @brief free log buffer and finish the log upload functions 40 | */ 41 | void fini_log_uploader(void); 42 | 43 | /** 44 | * @brief check if log uploader is init or not 45 | */ 46 | bool is_log_uploader_init(void); 47 | 48 | /** 49 | * @brief append one log item to upload buffer 50 | * 51 | * @param log_content 52 | * @param log_size 53 | * @return 0 when success, -1 when fail 54 | */ 55 | int append_to_upload_buffer(const char *log_content, size_t log_size); 56 | 57 | /** 58 | * @brief clear current upload buffer 59 | * 60 | * @return 61 | */ 62 | void clear_upload_buffer(void); 63 | 64 | /** 65 | * @brief do one upload to server 66 | * 67 | * @param force_upload if true, it will do upload right away, otherwise it will 68 | * check log_level, buffer left and upload interval 69 | * @return QCLOUD_RET_SUCCESS when success or no log to upload or timer is not 70 | * expired 71 | */ 72 | int do_log_upload(bool force_upload); 73 | 74 | /** 75 | * @brief set the log mqtt client to get system time 76 | * 77 | * @param client 78 | */ 79 | void set_log_mqtt_client(void *client); 80 | 81 | /** 82 | * @brief set if only do log upload when communication error with IoT Hub 83 | * 84 | * @param value if true, only do log upload when communication error with IoT 85 | * Hub 86 | */ 87 | void set_log_upload_in_comm_err(bool value); 88 | 89 | /** 90 | * @brief get current upload log_level from IoT Hub 91 | * 92 | * @param log_level 93 | * @return QCLOUD_RET_SUCCESS when success 94 | */ 95 | int qcloud_get_log_level(int *log_level); 96 | 97 | /** 98 | * @brief get the log mqtt client 99 | * 100 | * @return log mqtt client 101 | */ 102 | void *get_log_mqtt_client(void); 103 | 104 | /** 105 | * @brief get the device info of log client 106 | * 107 | * @return device info pointer of log client 108 | */ 109 | void * get_log_dev_info(void); 110 | 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif // QCLOUD_IOT_LOG_UPLOAD_H_ 117 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/mqtt_client_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_MQTT_CLIENT_NET_H_ 22 | #define IOT_MQTT_CLIENT_NET_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "network_interface.h" 29 | 30 | /** 31 | * @brief Init network stack 32 | * 33 | * @param pNetwork 34 | * @param pConnectParams 35 | * @return 0 for success 36 | */ 37 | int qcloud_iot_mqtt_network_init(Network *pNetwork); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif // IOT_MQTT_CLIENT_NET_H_ 44 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/ota_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_OTA_CLIENT_H_ 22 | #define IOT_OTA_CLIENT_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | /* Specify the maximum characters of version */ 31 | #define OTA_MAX_TOPIC_LEN (64) 32 | 33 | #define TYPE_FIELD "type" 34 | #define MD5_FIELD "md5sum" 35 | #define VERSION_FIELD "version" 36 | #define URL_FIELD "url" 37 | #define FILESIZE_FIELD "file_size" 38 | #define RESULT_FIELD "result_code" 39 | 40 | #define REPORT_VERSION_RSP "report_version_rsp" 41 | #define UPDATE_FIRMWARE "update_firmware" 42 | 43 | enum { MQTT_CHANNEL, COAP_CHANNEL }; 44 | 45 | typedef void (*OnOTAMessageCallback)(void *pcontext, const char *msg, uint32_t msgLen); 46 | 47 | void *qcloud_osc_init(const char *productId, const char *deviceName, void *channel, OnOTAMessageCallback callback, 48 | void *context); 49 | 50 | int qcloud_osc_deinit(void *handle); 51 | 52 | int qcloud_osc_report_progress(void *handle, const char *msg); 53 | 54 | int qcloud_osc_report_version(void *handle, const char *msg); 55 | 56 | int qcloud_osc_report_upgrade_result(void *handle, const char *msg); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* IOT_OTA_CLIENT_H_ */ 63 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/ota_fetch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_OTA_FETCH_H_ 22 | #define IOT_OTA_FETCH_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | void *ofc_Init(const char *url, uint32_t offset, uint32_t size); 31 | 32 | int32_t qcloud_ofc_connect(void *handle); 33 | 34 | int32_t qcloud_ofc_fetch(void *handle, char *buf, uint32_t buf_len, uint32_t timeout_s); 35 | 36 | int qcloud_ofc_deinit(void *handle); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* IOT_OTA_FETCH_H_ */ 43 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/ota_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_OTA_LIB_H_ 22 | #define IOT_OTA_LIB_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | #include 30 | 31 | #include "qcloud_iot_export_ota.h" 32 | 33 | void *qcloud_otalib_md5_init(void); 34 | 35 | void qcloud_otalib_md5_update(void *md5, const char *buf, size_t buf_len); 36 | 37 | void qcloud_otalib_md5_finalize(void *md5, char *output_str); 38 | 39 | void qcloud_otalib_md5_deinit(void *md5); 40 | 41 | int qcloud_otalib_get_firmware_type(const char *json, char **type); 42 | 43 | int qcloud_otalib_get_report_version_result(const char *json); 44 | 45 | /** 46 | * @brief Parse firmware info from JSON string 47 | * 48 | * @param json source JSON string 49 | * @param type parsed type 50 | * @param url parsed url 51 | * @param version parsed version 52 | * @param md5 parsed MD5 53 | * @param fileSize parsed file size 54 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 55 | */ 56 | int qcloud_otalib_get_params(const char *json, char **type, char **url, char **version, char *md5, uint32_t *fileSize); 57 | 58 | /** 59 | * @brief Generate firmware info from id and version 60 | * 61 | * @param buf output buffer 62 | * @param bufLen size of buffer 63 | * @param id firmware id 64 | * @param version firmware version 65 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 66 | */ 67 | int qcloud_otalib_gen_info_msg(char *buf, size_t bufLen, uint32_t id, const char *version); 68 | 69 | /** 70 | * @brief Generate firmware report 71 | * 72 | * @param buf output buffer 73 | * @param bufLen size of buffer 74 | * @param id firmware id 75 | * @param version firmware version 76 | * @param progress download progress 77 | * @param reportType report type 78 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 79 | */ 80 | int qcloud_otalib_gen_report_msg(char *buf, size_t bufLen, uint32_t id, const char *version, int progress, 81 | IOT_OTAReportType reportType); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* IOT_OTA_LIB_H_ */ 88 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/qcloud_iot_ca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_CA_H_ 22 | #define IOT_CA_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | const char *iot_ca_get(void); 29 | 30 | const char *iot_https_ca_get(void); 31 | 32 | const char *iot_get_mqtt_domain(char *region); 33 | 34 | const char *iot_get_dyn_reg_domain(char *region); 35 | 36 | const char *iot_get_log_domain(char *region); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* IOT_CA_H_ */ 43 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/qcloud_iot_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_COMMON_H_ 22 | #define QCLOUD_IOT_COMMON_H_ 23 | 24 | /* IoT C-SDK APPID */ 25 | #define QCLOUD_IOT_DEVICE_SDK_APPID "21010406" 26 | 27 | /* MQTT server domain */ 28 | #define QCLOUD_IOT_MQTT_DIRECT_DOMAIN "iotcloud.tencentdevices.com" 29 | #define QCLOUD_IOT_MQTT_US_EAST_DOMAIN "us-east.iotcloud.tencentdevices.com" 30 | 31 | #define MQTT_SERVER_PORT_TLS 8883 32 | #define MQTT_SERVER_PORT_NOTLS 1883 33 | 34 | /* CoAP server domain */ 35 | #define QCLOUD_IOT_COAP_DEIRECT_DOMAIN "iotcloud.tencentdevices.com" 36 | 37 | #define COAP_SERVER_PORT 5684 38 | 39 | /* server domain for dynamic registering device */ 40 | #define DYN_REG_SERVER_URL "gateway.tencentdevices.com" 41 | #define DYN_REG_SERVER_US_EAST_URL "us-east.gateway.tencentdevices.com" 42 | 43 | #define DYN_REG_SERVER_PORT 80 44 | #define DYN_REG_SERVER_PORT_TLS 443 45 | 46 | /* URL for doing log upload */ 47 | #define LOG_UPLOAD_SERVER_URL "http://devicelog.iot.cloud.tencent.com/cgi-bin/report-log" 48 | #define LOG_UPLOAD_SERVER_DOMAIN "devicelog.iot.cloud.tencent.com" 49 | #define LOG_UPLOAD_SERVER_US_EAST_DOMAIN "us-east.devicelog.iot.cloud.tencent.com" 50 | 51 | #define LOG_UPLOAD_SERVER_PORT 80 52 | 53 | /* Max size of a host name */ 54 | #define HOST_STR_LENGTH 64 55 | 56 | /* Max size of base64 encoded PSK = 64, after decode: 64/4*3 = 48*/ 57 | #define DECODE_PSK_LENGTH 48 58 | 59 | #endif /* QCLOUD_IOT_COMMON_H_ */ 60 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/qcloud_iot_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 IOT_DEVICE_H_ 22 | #define IOT_DEVICE_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "qcloud_iot_export.h" 29 | #include "qcloud_iot_import.h" 30 | 31 | int iot_device_info_set(DeviceInfo *device_info, const char *product_id, const char *device_name); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* IOT_DEVICE_H_ */ 38 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_BASE64_H_ 22 | #define QCLOUD_IOT_UTILS_BASE64_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | #include "qcloud_iot_export_error.h" 31 | #include "qcloud_iot_export_log.h" 32 | 33 | int qcloud_iot_utils_base64encode(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen); 34 | 35 | int qcloud_iot_utils_base64decode(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif /* QCLOUD_IOT_UTILS_BASE64_H_ */ 41 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_hmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_HMAC_H_ 22 | #define QCLOUD_IOT_UTILS_HMAC_H_ 23 | 24 | #include 25 | 26 | void utils_hmac_md5(const char *msg, int msg_len, char *digest, const char *key, int key_len); 27 | 28 | void utils_hmac_sha1(const char *msg, int msg_len, char *digest, const char *key, int key_len); 29 | 30 | int utils_hmac_sha1_hex(const char *msg, int msg_len, char *digest, const char *key, int key_len); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_httpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_HTTPC_H_ 22 | #define QCLOUD_IOT_UTILS_HTTPC_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | #include "network_interface.h" 31 | 32 | #define HTTP_PORT 80 33 | #define HTTPS_PORT 443 34 | 35 | typedef enum { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_HEAD } HttpMethod; 36 | 37 | typedef struct { 38 | int remote_port; 39 | int response_code; 40 | char * header; 41 | char * auth_user; 42 | char * auth_password; 43 | Network network_stack; 44 | } HTTPClient; 45 | 46 | typedef struct { 47 | bool is_more; // if more data to check 48 | bool is_chunked; // if response in chunked data 49 | int retrieve_len; // length of retrieve 50 | int response_content_len; // length of resposne content 51 | int post_buf_len; // post data length 52 | int response_buf_len; // length of response data buffer 53 | char *post_content_type; // type of post content 54 | char *post_buf; // post data buffer 55 | char *response_buf; // response data buffer 56 | } HTTPClientData; 57 | 58 | /** 59 | * @brief do one http request 60 | * 61 | * @param client http client 62 | * @param url server url 63 | * @param port server port 64 | * @param ca_crt_dir ca path 65 | * @param method type of request 66 | * @param client_data http data 67 | * @return QCLOUD_RET_SUCCESS for success, or err code for failure 68 | */ 69 | int qcloud_http_client_common(HTTPClient *client, const char *url, int port, const char *ca_crt, HttpMethod method, 70 | HTTPClientData *client_data); 71 | 72 | int qcloud_http_recv_data(HTTPClient *client, uint32_t timeout_ms, HTTPClientData *client_data); 73 | 74 | int qcloud_http_client_connect(HTTPClient *client, const char *url, int port, const char *ca_crt); 75 | 76 | void qcloud_http_client_close(HTTPClient *client); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | #endif /* QCLOUD_IOT_UTILS_HTTPC_H_ */ 82 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_LIST_H_ 22 | #define QCLOUD_IOT_UTILS_LIST_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | /* 31 | * ListNode iterator direction 32 | */ 33 | typedef enum { LIST_HEAD, LIST_TAIL } ListDirection; 34 | 35 | /* 36 | * define list node 37 | */ 38 | typedef struct ListNode { 39 | struct ListNode *prev; 40 | struct ListNode *next; 41 | void * val; 42 | } ListNode; 43 | 44 | /* 45 | * Double Linked List 46 | */ 47 | typedef struct { 48 | ListNode * head; 49 | ListNode * tail; 50 | unsigned int len; 51 | void (*free)(void *val); 52 | int (*match)(void *a, void *b); 53 | } List; 54 | 55 | /* 56 | * list iterator 57 | */ 58 | typedef struct { 59 | ListNode * next; 60 | ListDirection direction; 61 | } ListIterator; 62 | 63 | /* create node */ 64 | ListNode *list_node_new(void *val); 65 | 66 | /* create list */ 67 | List *list_new(void); 68 | 69 | ListNode *list_rpush(List *self, ListNode *node); 70 | 71 | ListNode *list_lpush(List *self, ListNode *node); 72 | 73 | ListNode *list_find(List *self, void *val); 74 | 75 | ListNode *list_at(List *self, int index); 76 | 77 | ListNode *list_rpop(List *self); 78 | 79 | ListNode *list_lpop(List *self); 80 | 81 | void list_remove(List *self, ListNode *node); 82 | 83 | void list_destroy(List *self); 84 | 85 | /* create iterator */ 86 | ListIterator *list_iterator_new(List *list, ListDirection direction); 87 | 88 | ListIterator *list_iterator_new_from_node(ListNode *node, ListDirection direction); 89 | 90 | ListNode *list_iterator_next(ListIterator *self); 91 | 92 | void list_iterator_destroy(ListIterator *self); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | #endif // QCLOUD_IOT_UTILS_LIST_H_ 98 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_MD5_H_ 22 | #define QCLOUD_IOT_UTILS_MD5_H_ 23 | 24 | #include "qcloud_iot_import.h" 25 | 26 | typedef struct { 27 | uint32_t total[2]; /*!< number of bytes processed */ 28 | uint32_t state[4]; /*!< intermediate digest state */ 29 | unsigned char buffer[64]; /*!< data block being processed */ 30 | } iot_md5_context; 31 | 32 | /** 33 | * @brief init MD5 context 34 | * 35 | * @param ctx MD5 context 36 | */ 37 | void utils_md5_init(iot_md5_context *ctx); 38 | 39 | /** 40 | * @brief free MD5 context 41 | * 42 | * @param ctx MD5 context 43 | */ 44 | void utils_md5_free(iot_md5_context *ctx); 45 | 46 | /** 47 | * @brief clone MD5 context 48 | * 49 | * @param dst destination MD5 context 50 | * @param src source MD5 context 51 | */ 52 | void utils_md5_clone(iot_md5_context *dst, const iot_md5_context *src); 53 | 54 | /** 55 | * @brief start MD5 calculation 56 | * 57 | * @param ctx MD5 context 58 | */ 59 | void utils_md5_starts(iot_md5_context *ctx); 60 | 61 | /** 62 | * @brief MD5 update 63 | * 64 | * @param ctx MD5 context 65 | * @param input input data 66 | * @param ilen data length 67 | */ 68 | void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, size_t ilen); 69 | 70 | /** 71 | * @brief finish MD5 calculation 72 | * 73 | * @param ctx MD5 context 74 | * @param output MD5 result 75 | */ 76 | void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]); 77 | 78 | /* MD5 internal process */ 79 | void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]); 80 | 81 | /** 82 | * @brief Output = MD5( input buffer ) 83 | * 84 | * @param input data input 85 | * @param ilen data lenght 86 | * @param output MD5 result 87 | */ 88 | void utils_md5(const unsigned char *input, size_t ilen, unsigned char output[16]); 89 | 90 | /** 91 | * @brief Output = MD5( input buffer ) 92 | * 93 | * @param input data input 94 | * @param ilen data lenght 95 | * @param output string MD5 result 96 | */ 97 | void utils_md5_str(const unsigned char *input, size_t ilen, unsigned char *output); 98 | 99 | int8_t utils_hb2hex(uint8_t hb); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_ringbuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 __AT_RING_BUFF_H__ 22 | #define __AT_RING_BUFF_H__ 23 | 24 | #include "stdbool.h" 25 | #include "stdint.h" 26 | 27 | #define RINGBUFF_OK 0 /* No error, everything OK. */ 28 | #define RINGBUFF_ERR -1 /* Out of memory error. */ 29 | #define RINGBUFF_EMPTY -3 /* Timeout. */ 30 | #define RINGBUFF_FULL -4 /* Routing problem. */ 31 | #define RINGBUFF_TOO_SHORT -5 32 | 33 | typedef struct _ring_buff_ { 34 | uint32_t size; 35 | uint32_t readpoint; 36 | uint32_t writepoint; 37 | char * buffer; 38 | bool full; 39 | } sRingbuff; 40 | 41 | typedef sRingbuff *ring_buff_t; 42 | 43 | int ring_buff_init(sRingbuff *ring_buff, char *buff, uint32_t size); 44 | int ring_buff_flush(sRingbuff *ring_buff); 45 | int ring_buff_push_data(sRingbuff *ring_buff, uint8_t *pData, int len); 46 | int ring_buff_pop_data(sRingbuff *ring_buff, uint8_t *pData, int len); 47 | #endif // __ringbuff_h__ 48 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_SHA1_H_ 22 | #define QCLOUD_IOT_UTILS_SHA1_H_ 23 | 24 | #include "qcloud_iot_import.h" 25 | 26 | /** 27 | * \brief SHA-1 context structure 28 | */ 29 | typedef struct { 30 | uint32_t total[2]; /*!< number of bytes processed */ 31 | uint32_t state[5]; /*!< intermediate digest state */ 32 | unsigned char buffer[64]; /*!< data block being processed */ 33 | } iot_sha1_context; 34 | 35 | /** 36 | * \brief Initialize SHA-1 context 37 | * 38 | * \param ctx SHA-1 context to be initialized 39 | */ 40 | void utils_sha1_init(iot_sha1_context *ctx); 41 | 42 | /** 43 | * \brief Clear SHA-1 context 44 | * 45 | * \param ctx SHA-1 context to be cleared 46 | */ 47 | void utils_sha1_free(iot_sha1_context *ctx); 48 | 49 | /** 50 | * \brief Clone (the state of) a SHA-1 context 51 | * 52 | * \param dst The destination context 53 | * \param src The context to be cloned 54 | */ 55 | void utils_sha1_clone(iot_sha1_context *dst, const iot_sha1_context *src); 56 | 57 | /** 58 | * \brief SHA-1 context setup 59 | * 60 | * \param ctx context to be initialized 61 | */ 62 | void utils_sha1_starts(iot_sha1_context *ctx); 63 | 64 | /** 65 | * \brief SHA-1 process buffer 66 | * 67 | * \param ctx SHA-1 context 68 | * \param input buffer holding the data 69 | * \param ilen length of the input data 70 | */ 71 | void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, size_t ilen); 72 | 73 | /** 74 | * \brief SHA-1 final digest 75 | * 76 | * \param ctx SHA-1 context 77 | * \param output SHA-1 checksum result 78 | */ 79 | void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20]); 80 | 81 | /* Internal use */ 82 | void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64]); 83 | 84 | /** 85 | * \brief Output = SHA-1( input buffer ) 86 | * 87 | * \param input buffer holding the data 88 | * \param ilen length of the input data 89 | * \param output SHA-1 checksum result 90 | */ 91 | void utils_sha1(const unsigned char *input, size_t ilen, unsigned char output[20]); 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal_inc/utils_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 QCLOUD_IOT_UTILS_TIMER_H_ 22 | #define QCLOUD_IOT_UTILS_TIMER_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | // Add the platform specific timer includes to define the Timer struct 29 | #include "qcloud_iot_import.h" 30 | 31 | /** 32 | * @brief Check if a timer is expired 33 | * 34 | * Call this function passing in a timer to check if that timer has expired. 35 | * 36 | * @param timer - pointer to the timer to be checked for expiration 37 | * @return bool - true = timer expired, false = timer not expired 38 | */ 39 | bool expired(Timer *timer); 40 | 41 | /** 42 | * @brief Create a timer (milliseconds) 43 | * 44 | * Sets the timer to expire in a specified number of milliseconds. 45 | * 46 | * @param timer - pointer to the timer to be set to expire in milliseconds 47 | * @param timeout_ms - set the timer to expire in this number of milliseconds 48 | */ 49 | void countdown_ms(Timer *timer, unsigned int timeout_ms); 50 | 51 | /** 52 | * @brief Create a timer (seconds) 53 | * 54 | * Sets the timer to expire in a specified number of seconds. 55 | * 56 | * @param timer - pointer to the timer to be set to expire in seconds 57 | * @param timeout - set the timer to expire in this number of seconds 58 | */ 59 | void countdown(Timer *timer, unsigned int timeout); 60 | 61 | /** 62 | * @brief Check the time remaining on a give timer 63 | * 64 | * Checks the input timer and returns the number of milliseconds remaining on 65 | * the timer. 66 | * 67 | * @param timer - pointer to the timer to be set to checked 68 | * @return int - milliseconds left on the countdown timer 69 | */ 70 | int left_ms(Timer *timer); 71 | 72 | /** 73 | * @brief Initialize a timer 74 | * 75 | * Performs any initialization required to the timer passed in. 76 | * 77 | * @param timer - pointer to the timer to be initialized 78 | */ 79 | void InitTimer(Timer *timer); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif // QCLOUD_IOT_UTILS_TIMER_H_ 86 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/protocol/mqtt/mqtt_client_net.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2018-2020 THL A29 Limited, a Tencent company. All rights 5 | reserved. 6 | 7 | * Licensed under the MIT License (the "License"); you may not use this file 8 | except in 9 | * compliance with the License. You may obtain a copy of the License at 10 | * http://opensource.org/licenses/MIT 11 | 12 | * Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is 14 | * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, 16 | * either express or implied. See the License for the specific language 17 | governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "mqtt_client_net.h" 27 | 28 | // TODO: how to implement 29 | /** 30 | * @brief Check if TLS connection is valid 31 | * 32 | * @param pNetwork 33 | * @return 34 | */ 35 | int qcloud_iot_mqtt_tls_is_connected(Network *pNetwork) 36 | { 37 | return 1; 38 | } 39 | 40 | /** 41 | * @brief Init network stack 42 | * 43 | * @param pNetwork 44 | * @param pConnectParams 45 | * @return 46 | */ 47 | int qcloud_iot_mqtt_network_init(Network *pNetwork) 48 | { 49 | int rc; 50 | 51 | /* first choice: TLS */ 52 | pNetwork->type = NETWORK_TLS; 53 | 54 | #ifdef AUTH_WITH_NOTLS 55 | pNetwork->type = NETWORK_TCP; 56 | #endif 57 | 58 | rc = network_init(pNetwork); 59 | pNetwork->is_connected = qcloud_iot_mqtt_tls_is_connected; 60 | 61 | return rc; 62 | } 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/utils/qcloud_iot_device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | #include "qcloud_iot_device.h" 25 | 26 | #include 27 | #include 28 | 29 | #include "qcloud_iot_export.h" 30 | 31 | int iot_device_info_set(DeviceInfo *device_info, const char *product_id, const char *device_name) 32 | { 33 | memset(device_info, 0x0, sizeof(DeviceInfo)); 34 | if ((MAX_SIZE_OF_PRODUCT_ID) < strlen(product_id)) { 35 | Log_e("product name(%s) length:(%lu) exceeding limitation", product_id, strlen(product_id)); 36 | return QCLOUD_ERR_FAILURE; 37 | } 38 | if ((MAX_SIZE_OF_DEVICE_NAME) < strlen(device_name)) { 39 | Log_e("device name(%s) length:(%lu) exceeding limitation", device_name, strlen(device_name)); 40 | return QCLOUD_ERR_FAILURE; 41 | } 42 | 43 | strncpy(device_info->product_id, product_id, MAX_SIZE_OF_PRODUCT_ID); 44 | strncpy(device_info->device_name, device_name, MAX_SIZE_OF_DEVICE_NAME); 45 | 46 | /* construct device-id(@product_id+@device_name) */ 47 | memset(device_info->client_id, 0x0, MAX_SIZE_OF_CLIENT_ID); 48 | int ret = HAL_Snprintf(device_info->client_id, MAX_SIZE_OF_CLIENT_ID, "%s%s", product_id, device_name); 49 | if ((ret < 0) || (ret >= MAX_SIZE_OF_CLIENT_ID)) { 50 | Log_e("set device info failed"); 51 | return QCLOUD_ERR_FAILURE; 52 | } 53 | 54 | Log_i("SDK_Ver: %s, Product_ID: %s, Device_Name: %s", QCLOUD_IOT_DEVICE_SDK_VERSION, device_info->product_id, 55 | device_info->device_name); 56 | return QCLOUD_RET_SUCCESS; 57 | } 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/utils/utils_getopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 Tencent Group. All rights reserved. 3 | * License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | * not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | #include "utils_getopt.h" 20 | 21 | #include 22 | #include 23 | 24 | #include "qcloud_iot_import.h" 25 | 26 | static int utils_opterr = 1; /* if error message should be printed */ 27 | static int utils_optind = 1; /* index into parent argv vector */ 28 | static int utils_optopt; /* character checked for validity */ 29 | static int utils_optreset = 1; /* reset getopt */ 30 | 31 | char *utils_optarg; /* argument associated with option */ 32 | 33 | int utils_getopt(int nargc, char *const *nargv, const char *options) 34 | { 35 | #define BADCH (int)'?' 36 | #define BADARG (int)':' 37 | #define EMSG "" 38 | 39 | static char *place = EMSG; /* option letter processing */ 40 | const char * oli; /* option letter list index */ 41 | 42 | if (utils_optreset || !*place) { /* update scanning pointer */ 43 | utils_optreset = 0; 44 | 45 | if (utils_optind >= nargc || *(place = nargv[utils_optind]) != '-') { 46 | utils_optind = 1; 47 | utils_optreset = 1; 48 | place = EMSG; 49 | return (-1); 50 | } 51 | 52 | place++; 53 | } 54 | 55 | /* option letter okay? */ 56 | if ((utils_optopt = (int)*place++) == (int)':' || !(oli = strchr(options, utils_optopt))) { 57 | /* 58 | * if the user didn't specify '-' as an option, 59 | * assume it means -1. 60 | */ 61 | if (utils_optopt == (int)'-') 62 | return (-1); 63 | 64 | if (!*place) 65 | ++utils_optind; 66 | 67 | if (utils_opterr && *options != ':') 68 | HAL_Printf("illegal option - %c\n", utils_optopt); 69 | 70 | return (BADCH); 71 | } 72 | 73 | if (*++oli != ':') { /* don't need argument */ 74 | utils_optarg = NULL; 75 | if (!*place) 76 | ++utils_optind; 77 | } else { 78 | /* need an argument */ 79 | if (*place) /* no white space */ 80 | utils_optarg = place; 81 | else if (nargc <= ++utils_optind) { /* no arg */ 82 | place = EMSG; 83 | if (*options == ':') 84 | return (BADARG); 85 | if (utils_opterr) 86 | HAL_Printf("option requires an argument - %c\n", utils_optopt); 87 | return (BADCH); 88 | } else /* white space */ 89 | utils_optarg = nargv[utils_optind]; 90 | 91 | place = EMSG; 92 | ++utils_optind; 93 | } 94 | 95 | /* dump back option letter */ 96 | return (utils_optopt); 97 | } 98 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/utils/utils_ringbuff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 | #include "utils_ringbuff.h" 22 | 23 | #include 24 | #include 25 | 26 | int ring_buff_init(sRingbuff *ring_buff, char *buff, uint32_t size) 27 | { 28 | ring_buff->buffer = buff; 29 | ring_buff->size = size; 30 | ring_buff->readpoint = 0; 31 | ring_buff->writepoint = 0; 32 | memset(ring_buff->buffer, 0, ring_buff->size); 33 | ring_buff->full = false; 34 | 35 | return RINGBUFF_OK; 36 | } 37 | 38 | int ring_buff_flush(sRingbuff *ring_buff) 39 | { 40 | ring_buff->readpoint = 0; 41 | ring_buff->writepoint = 0; 42 | memset(ring_buff->buffer, 0, ring_buff->size); 43 | ring_buff->full = false; 44 | 45 | return RINGBUFF_OK; 46 | } 47 | 48 | int ring_buff_push_data(sRingbuff *ring_buff, uint8_t *pData, int len) 49 | { 50 | int i; 51 | 52 | if (len > ring_buff->size) { 53 | return RINGBUFF_TOO_SHORT; 54 | } 55 | 56 | for (i = 0; i < len; i++) { 57 | if (((ring_buff->writepoint + 1) % ring_buff->size) == ring_buff->readpoint) { 58 | ring_buff->full = true; 59 | return RINGBUFF_FULL; 60 | } else { 61 | if (ring_buff->writepoint < (ring_buff->size - 1)) { 62 | ring_buff->writepoint++; 63 | } else { 64 | ring_buff->writepoint = 0; 65 | } 66 | ring_buff->buffer[ring_buff->writepoint] = pData[i]; 67 | } 68 | } 69 | 70 | return RINGBUFF_OK; 71 | } 72 | 73 | int ring_buff_pop_data(sRingbuff *ring_buff, uint8_t *pData, int len) 74 | { 75 | int i; 76 | 77 | if (len > ring_buff->size) { 78 | return RINGBUFF_TOO_SHORT; 79 | } 80 | 81 | for (i = 0; i < len; i++) { 82 | if (ring_buff->writepoint == ring_buff->readpoint) { 83 | break; 84 | } else { 85 | if (ring_buff->readpoint == (ring_buff->size - 1)) { 86 | ring_buff->readpoint = 0; 87 | } 88 | 89 | else { 90 | ring_buff->readpoint++; 91 | } 92 | pData[i] = ring_buff->buffer[ring_buff->readpoint]; 93 | } 94 | } 95 | 96 | return i; 97 | } 98 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/sdk_src/utils/utils_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tencent is pleased to support the open source community by making IoT Hub 3 | available. 4 | * Copyright (C) 2016 THL A29 Limited, a Tencent company. 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 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "utils_timer.h" 26 | 27 | bool expired(Timer *timer) 28 | { 29 | return HAL_Timer_expired(timer); 30 | } 31 | 32 | void countdown_ms(Timer *timer, unsigned int timeout_ms) 33 | { 34 | HAL_Timer_countdown_ms(timer, timeout_ms); 35 | } 36 | 37 | void countdown(Timer *timer, unsigned int timeout) 38 | { 39 | HAL_Timer_countdown(timer, timeout); 40 | } 41 | 42 | int left_ms(Timer *timer) 43 | { 44 | return HAL_Timer_remain(timer); 45 | } 46 | 47 | void InitTimer(Timer *timer) 48 | { 49 | HAL_Timer_init(timer); 50 | } 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/tools/build_scripts/parse_make_settings.mk: -------------------------------------------------------------------------------- 1 | include $(SCRIPT_DIR)/internal_make_funcs.mk 2 | 3 | FEATURE_DATA_TEMPLATE_ENABLED = y 4 | FEATURE_OTA_SIGNAL_CHANNEL = MQTT 5 | 6 | SETTING_VARS := \ 7 | BUILD_TYPE \ 8 | PLATFORM_CC \ 9 | PLATFORM_AR \ 10 | PLATFORM_OS \ 11 | 12 | SWITCH_VARS := \ 13 | FEATURE_MQTT_COMM_ENABLED \ 14 | FEATURE_OTA_COMM_ENABLED \ 15 | FEATURE_AUTH_WITH_NOTLS \ 16 | FEATURE_GATEWAY_ENABLED \ 17 | FEATURE_LOG_UPLOAD_ENABLED \ 18 | FEATURE_DEV_DYN_REG_ENABLED \ 19 | FEATURE_AT_TCP_ENABLED \ 20 | FEATURE_AT_UART_RECV_IRQ \ 21 | FEATURE_AT_OS_USED \ 22 | FEATURE_AT_DEBUG \ 23 | FEATURE_DATA_TEMPLATE_ENABLED \ 24 | FEATURE_EVENT_POST_ENABLED \ 25 | FEATURE_ACTION_ENABLED \ 26 | FEATURE_DEBUG_DEV_INFO_USED \ 27 | FEATURE_SYSTEM_COMM_ENABLED \ 28 | FEATURE_OTA_USE_HTTPS \ 29 | FEATURE_MULTITHREAD_ENABLED \ 30 | 31 | 32 | 33 | $(foreach v, \ 34 | $(SETTING_VARS) $(SWITCH_VARS), \ 35 | $(eval export $(v)=$($(v))) \ 36 | ) 37 | 38 | $(foreach v, \ 39 | $(SWITCH_VARS), \ 40 | $(if $(filter y,$($(v))), \ 41 | $(eval CFLAGS += -D$(subst FEATURE_,,$(v)))) \ 42 | ) 43 | 44 | 45 | ifeq (debug,$(strip $(BUILD_TYPE))) 46 | CFLAGS += -DIOT_DEBUG -g -O2 47 | endif 48 | 49 | ifneq (linux,$(strip $(PLATFORM_OS))) 50 | ifeq (y,$(strip $(FEATURE_SDKTESTS_ENABLED))) 51 | $(error FEATURE_SDKTESTS_ENABLED with gtest framework just supports to be enabled on PLATFORM_OS = linux!) 52 | endif 53 | else 54 | ifeq (y,$(strip $(FEATURE_SDKTESTS_ENABLED))) 55 | CFLAGS += -DSDKTESTS_ENABLED 56 | endif 57 | endif 58 | 59 | ifeq (y,$(strip $(FEATURE_OTA_COMM_ENABLED))) 60 | ifeq (MQTT,$(strip $(FEATURE_OTA_SIGNAL_CHANNEL))) 61 | ifneq (y,$(strip $(FEATURE_MQTT_COMM_ENABLED))) 62 | $(error FEATURE_OTA_SIGNAL_CHANNEL = MQTT requires FEATURE_MQTT_COMM_ENABLED = y!) 63 | endif 64 | CFLAGS += -DOTA_MQTT_CHANNEL 65 | else 66 | ifeq (COAP,$(strip $(FEATURE_OTA_SIGNAL_CHANNEL))) 67 | ifneq (y,$(strip $(FEATURE_COAP_COMM_ENABLED))) 68 | $(error FEATURE_OTA_SIGNAL_CHANNEL = COAP requires FEATURE_COAP_COMM_ENABLED = y!) 69 | endif 70 | CFLAGS += -DOTA_COAP_CHANNEL 71 | else 72 | $(error FEATURE_OTA_SIGNAL_CHANNEL must be MQTT or COAP!) 73 | endif # COAP 74 | endif # MQTT 75 | endif # OTA Enabled 76 | 77 | ifeq (CERT,$(strip $(FEATURE_AUTH_MODE))) 78 | ifeq (y,$(strip $(FEATURE_AUTH_WITH_NOTLS))) 79 | $(error FEATURE_AUTH_MODE = CERT requires FEATURE_AUTH_WITH_NOTLS = n!) 80 | endif 81 | CFLAGS += -DAUTH_MODE_CERT 82 | else 83 | ifeq (KEY,$(strip $(FEATURE_AUTH_MODE))) 84 | CFLAGS += -DAUTH_MODE_KEY 85 | else 86 | $(error FEATURE_AUTH_MODE must be CERT or KEY!) 87 | endif 88 | endif # Auth mode 89 | 90 | ifeq (y,$(strip $(FEATURE_OTA_USE_HTTPS))) 91 | ifeq (y,$(strip $(FEATURE_AUTH_WITH_NOTLS))) 92 | $(error FEATURE_OTA_USE_HTTPS = y requires FEATURE_AUTH_WITH_NOTLS = n!) 93 | endif 94 | endif 95 | 96 | ifeq (y, $(strip $(FEATURE_SYSTEM_COMM_ENABLED))) 97 | CFLAGS += -DSYSTEM_COMM 98 | endif 99 | 100 | ifeq (y, $(strip $(FEATURE_LOG_UPLOAD_ENABLED))) 101 | CFLAGS += -DLOG_UPLOAD 102 | endif 103 | 104 | ifeq (y, $(strip $(FEATURE_GATEWAY_ENABLED))) 105 | CFLAGS += -DMULTITHREAD_ENABLED 106 | endif 107 | 108 | ifeq (y, $(strip $(FEATURE_AT_OS_USED))) 109 | CFLAGS += -DAT_OS_USED 110 | endif 111 | 112 | ifeq (y, $(strip $(FEATURE_AT_DEBUG))) 113 | CFLAGS += -DFEATURE_AT_DEBUG 114 | endif 115 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 clean final-out samples tests 5 | 6 | all: config mbedtls ${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 | 29 | mbedtls: 30 | ifeq (,$(filter -DAUTH_WITH_NOTLS,$(CFLAGS))) 31 | $(TOP_Q) \ 32 | make -s -C $(THIRD_PARTY_PATH)/mbedtls lib -e CC=$(PLATFORM_CC) AR=$(PLATFORM_AR) 33 | 34 | $(TOP_Q) \ 35 | cp -RP $(THIRD_PARTY_PATH)/mbedtls/library/libmbedtls.* \ 36 | $(THIRD_PARTY_PATH)/mbedtls/library/libmbedx509.* \ 37 | $(THIRD_PARTY_PATH)/mbedtls/library/libmbedcrypto.* \ 38 | $(TEMP_DIR) 39 | 40 | $(TOP_Q) \ 41 | cd $(TEMP_DIR) && $(AR) x libmbedtls.a \ 42 | && $(AR) x libmbedx509.a \ 43 | && $(AR) x libmbedcrypto.a 44 | endif 45 | 46 | ${iot_sdk_objects}:%.o:%.c 47 | $(TOP_Q) echo '' > $(TOP_DIR)/include/config.h 48 | $(call Brief_Log,"CC") 49 | $(TOP_Q) \ 50 | $(PLATFORM_CC) $(CFLAGS) -c $^ -o $@ 51 | 52 | ${iot_platform_objects}:%.o:%.c 53 | $(call Brief_Log,"CC") 54 | $(TOP_Q) \ 55 | $(PLATFORM_CC) $(CFLAGS) -c $^ -o $@ 56 | 57 | final-out : 58 | $(TOP_Q) \ 59 | mkdir -p ${FINAL_DIR} ${DIST_DIR} ${FINAL_DIR}/lib \ 60 | ${FINAL_DIR}/include ${FINAL_DIR}/bin 61 | 62 | $(TOP_Q) \ 63 | mv ${COMP_LIB} ${FINAL_DIR}/lib/ && \ 64 | mv ${PLATFORM_LIB} ${FINAL_DIR}/lib 65 | 66 | $(TOP_Q) \ 67 | cp -rf $(TOP_DIR)/include $(FINAL_DIR)/ 68 | 69 | $(TOP_Q) \ 70 | cp -rf $(TOP_DIR)/certs $(FINAL_DIR)/bin/ 71 | 72 | $(TOP_Q) \ 73 | cp -rf $(TOP_DIR)/device_info.json $(FINAL_DIR)/bin/ 74 | 75 | ifeq (,$(filter -DAUTH_WITH_NOTLS,$(CFLAGS))) 76 | $(TOP_Q) \ 77 | mv ${TEMP_DIR}/*.a ${FINAL_DIR}/lib/ 78 | endif 79 | 80 | $(TOP_Q) \ 81 | rm -rf ${TEMP_DIR} 82 | 83 | #include $(SCRIPT_DIR)/rules-tests.mk 84 | 85 | samples: 86 | $(TOP_Q) \ 87 | make -s -C $(SAMPLE_DIR) 88 | 89 | TLSDIR = $(THIRD_PARTY_PATH)/mbedtls 90 | clean: 91 | $(TOP_Q) \ 92 | rm -rf ${TEMP_DIR} 93 | 94 | $(TOP_Q) \ 95 | rm -rf ${DIST_DIR} 96 | 97 | ifeq (,$(filter -DAUTH_WITH_NOTLS,$(CFLAGS))) 98 | ifeq ($(TLSDIR), $(wildcard $(THIRD_PARTY_PATH)/mbedtls)) 99 | $(TOP_Q) \ 100 | make -s -C $(THIRD_PARTY_PATH)/mbedtls clean 101 | endif 102 | endif 103 | 104 | ifeq (,$(filter -DSDKTESTS_ENABLED,$(CFLAGS))) 105 | $(TOP_Q) \ 106 | rm -rf $(TEST_LIB_DIR) 107 | endif 108 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 EVENT_POST_ENABLED 9 | #cmakedefine ACTION_ENABLED 10 | #cmakedefine DEV_DYN_REG_ENABLED 11 | #cmakedefine LOG_UPLOAD 12 | #cmakedefine IOT_DEBUG 13 | #cmakedefine DEBUG_DEV_INFO_USED 14 | #cmakedefine AT_TCP_ENABLED 15 | #cmakedefine AT_UART_RECV_IRQ 16 | #cmakedefine AT_OS_USED 17 | #cmakedefine AT_DEBUG 18 | #cmakedefine OTA_USE_HTTPS 19 | #cmakedefine GATEWAY_ENABLED 20 | #cmakedefine MULTITHREAD_ENABLED 21 | #cmakedefine GATEWAY_DYN_BIND_SUBDEV_ENABLED 22 | -------------------------------------------------------------------------------- /qcloud-iot-explorer-sdk-embedded-c/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 | -------------------------------------------------------------------------------- /samples/data_template/action_config.c: -------------------------------------------------------------------------------- 1 | #ifdef ACTION_ENABLED 2 | 3 | #define TOTAL_ACTION_COUNTS (1) 4 | 5 | static TYPE_DEF_TEMPLATE_INT sg_light_blink_in_time = 0; 6 | static TYPE_DEF_TEMPLATE_BOOL sg_light_blink_in_color = 0; 7 | static TYPE_DEF_TEMPLATE_INT sg_light_blink_in_total_time = 0; 8 | static DeviceProperty g_actionInput_light_blink[] = { 9 | 10 | {.key = "time", .data = &sg_light_blink_in_time, .type = TYPE_TEMPLATE_INT}, 11 | {.key = "color", .data = &sg_light_blink_in_color, .type = TYPE_TEMPLATE_BOOL}, 12 | {.key = "total_time", .data = &sg_light_blink_in_total_time, .type = TYPE_TEMPLATE_INT}, 13 | }; 14 | static TYPE_DEF_TEMPLATE_BOOL sg_light_blink_out_err_code = 0; 15 | static DeviceProperty g_actionOutput_light_blink[] = { 16 | 17 | {.key = "err_code", .data = &sg_light_blink_out_err_code, .type = TYPE_TEMPLATE_BOOL}, 18 | }; 19 | 20 | 21 | static DeviceAction g_actions[] = { 22 | 23 | { 24 | .pActionId = "light_blink", 25 | .timestamp = 0, 26 | .input_num = sizeof(g_actionInput_light_blink) / sizeof(g_actionInput_light_blink[0]), 27 | .output_num = sizeof(g_actionOutput_light_blink) / sizeof(g_actionOutput_light_blink[0]), 28 | .pInput = g_actionInput_light_blink, 29 | .pOutput = g_actionOutput_light_blink, 30 | }, 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /samples/data_template/data_config.c: -------------------------------------------------------------------------------- 1 | /*-----------------data config start -------------------*/ 2 | 3 | #define TOTAL_PROPERTY_COUNT 4 4 | 5 | static sDataPoint sg_DataTemplate[TOTAL_PROPERTY_COUNT]; 6 | 7 | typedef struct _ProductDataDefine { 8 | TYPE_DEF_TEMPLATE_BOOL m_power_switch; 9 | TYPE_DEF_TEMPLATE_ENUM m_color; 10 | TYPE_DEF_TEMPLATE_INT m_brightness; 11 | TYPE_DEF_TEMPLATE_STRING m_name[64 + 1]; 12 | } ProductDataDefine; 13 | 14 | static ProductDataDefine sg_ProductData; 15 | 16 | static void _init_data_template(void) 17 | { 18 | sg_ProductData.m_power_switch = 0; 19 | sg_DataTemplate[0].data_property.data = &sg_ProductData.m_power_switch; 20 | sg_DataTemplate[0].data_property.key = "power_switch"; 21 | sg_DataTemplate[0].data_property.type = TYPE_TEMPLATE_BOOL; 22 | 23 | sg_ProductData.m_color = 0; 24 | sg_DataTemplate[1].data_property.data = &sg_ProductData.m_color; 25 | sg_DataTemplate[1].data_property.key = "color"; 26 | sg_DataTemplate[1].data_property.type = TYPE_TEMPLATE_ENUM; 27 | 28 | sg_ProductData.m_brightness = 1; 29 | sg_DataTemplate[2].data_property.data = &sg_ProductData.m_brightness; 30 | sg_DataTemplate[2].data_property.key = "brightness"; 31 | sg_DataTemplate[2].data_property.type = TYPE_TEMPLATE_INT; 32 | 33 | sg_ProductData.m_name[0] = '\0'; 34 | sg_DataTemplate[3].data_property.data = sg_ProductData.m_name; 35 | sg_DataTemplate[3].data_property.data_buff_len = sizeof(sg_ProductData.m_name) / sizeof(sg_ProductData.m_name[3]); 36 | sg_DataTemplate[3].data_property.key = "name"; 37 | sg_DataTemplate[3].data_property.type = TYPE_TEMPLATE_STRING; 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /samples/data_template/events_config.c: -------------------------------------------------------------------------------- 1 | #ifdef EVENT_POST_ENABLED 2 | 3 | #define EVENT_COUNTS (3) 4 | 5 | static TYPE_DEF_TEMPLATE_BOOL sg_status_report_status = 0; 6 | static TYPE_DEF_TEMPLATE_STRING sg_status_report_message[64 + 1] = {0}; 7 | static DeviceProperty g_propertyEvent_status_report[] = { 8 | 9 | {.key = "status", .data = &sg_status_report_status, .type = TYPE_TEMPLATE_BOOL}, 10 | {.key = "message", .data = sg_status_report_message, .type = TYPE_TEMPLATE_STRING}, 11 | }; 12 | 13 | static TYPE_DEF_TEMPLATE_FLOAT sg_low_voltage_voltage = 1; 14 | static DeviceProperty g_propertyEvent_low_voltage[] = { 15 | 16 | {.key = "voltage", .data = &sg_low_voltage_voltage, .type = TYPE_TEMPLATE_FLOAT}, 17 | }; 18 | 19 | static TYPE_DEF_TEMPLATE_STRING sg_hardware_fault_name[64 + 1] = {0}; 20 | static TYPE_DEF_TEMPLATE_INT sg_hardware_fault_error_code = 1; 21 | static DeviceProperty g_propertyEvent_hardware_fault[] = { 22 | 23 | {.key = "name", .data = sg_hardware_fault_name, .type = TYPE_TEMPLATE_STRING}, 24 | {.key = "error_code", .data = &sg_hardware_fault_error_code, .type = TYPE_TEMPLATE_INT}, 25 | }; 26 | 27 | 28 | static sEvent g_events[] = { 29 | 30 | { 31 | .event_name = "status_report", 32 | .type = "info", 33 | .timestamp = 0, 34 | .eventDataNum = sizeof(g_propertyEvent_status_report) / sizeof(g_propertyEvent_status_report[0]), 35 | .pEventData = g_propertyEvent_status_report, 36 | }, 37 | { 38 | .event_name = "low_voltage", 39 | .type = "alert", 40 | .timestamp = 0, 41 | .eventDataNum = sizeof(g_propertyEvent_low_voltage) / sizeof(g_propertyEvent_low_voltage[0]), 42 | .pEventData = g_propertyEvent_low_voltage, 43 | }, 44 | { 45 | .event_name = "hardware_fault", 46 | .type = "fault", 47 | .timestamp = 0, 48 | .eventDataNum = sizeof(g_propertyEvent_hardware_fault) / sizeof(g_propertyEvent_hardware_fault[0]), 49 | .pEventData = g_propertyEvent_hardware_fault, 50 | }, 51 | }; 52 | 53 | #endif 54 | --------------------------------------------------------------------------------