├── .gitignore ├── .gitlab-ci.yml ├── CMakeLists.txt ├── Kconfig ├── README.md ├── component.mk ├── config └── mass_mfg │ ├── README.md │ ├── multipule_mfg_config.csv │ ├── multipule_mfg_values.csv │ └── single_mfg_config.csv ├── conn_mgr ├── conn_mgr.c └── conn_mgr.h ├── docs ├── _static │ ├── p1.png │ ├── p2.png │ ├── p3.png │ └── p4.png └── issue_template.md ├── examples ├── awss │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── _static │ │ ├── p1.png │ │ ├── p2.png │ │ ├── p3.png │ │ ├── p4.png │ │ └── p5.png │ ├── main │ │ ├── CMakeLists.txt │ │ ├── app_main.c │ │ └── component.mk │ ├── partitions_esp32.csv │ ├── partitions_esp8266.csv │ ├── sdkconfig_esp32.defaults │ └── sdkconfig_esp8266.defaults ├── mqtt │ └── mqtt_example │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── _static │ │ ├── p1.png │ │ ├── p2.png │ │ ├── p3.png │ │ ├── p4.png │ │ └── p5.png │ │ ├── components │ │ └── mqtt_handle │ │ │ ├── CMakeLists.txt │ │ │ ├── component.mk │ │ │ ├── mqtt_solo.c │ │ │ └── mqtt_solo.h │ │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ └── component.mk │ │ ├── partitions_esp32.csv │ │ ├── partitions_esp8266.csv │ │ ├── sdkconfig_esp32.defaults │ │ └── sdkconfig_esp8266.defaults ├── ota │ └── ota_example_mqtt │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── _static │ │ ├── p1.png │ │ ├── p2.png │ │ ├── p3.png │ │ ├── p4.png │ │ ├── p5.png │ │ └── p6.png │ │ ├── components │ │ └── ota_handle │ │ │ ├── CMakeLists.txt │ │ │ ├── component.mk │ │ │ ├── ota_solo.c │ │ │ └── ota_solo.h │ │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ └── component.mk │ │ ├── partitions_esp32.csv │ │ ├── partitions_esp8266.csv │ │ ├── sdkconfig_esp32.defaults │ │ └── sdkconfig_esp8266.defaults ├── solo │ └── example_solo │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── components │ │ ├── databases │ │ │ ├── CMakeLists.txt │ │ │ ├── app_entry.c │ │ │ ├── app_entry.h │ │ │ └── component.mk │ │ ├── linkkit_handle │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig │ │ │ ├── component.mk │ │ │ ├── linkkit_solo.c │ │ │ └── linkkit_solo.h │ │ └── transports │ │ │ ├── CMakeLists.txt │ │ │ ├── component.mk │ │ │ ├── transport_data.h │ │ │ ├── transport_uart.c │ │ │ └── transport_uart.h │ │ ├── main │ │ ├── CMakeLists.txt │ │ ├── app_main.c │ │ └── component.mk │ │ ├── partitions_esp32.csv │ │ ├── partitions_esp32s2.csv │ │ ├── partitions_esp32s3.csv │ │ ├── partitions_esp8266.csv │ │ ├── sdkconfig.defaults │ │ ├── sdkconfig.defaults.esp32s2 │ │ ├── sdkconfig.defaults.esp32s3 │ │ ├── sdkconfig_esp32.defaults │ │ └── sdkconfig_esp8266.defaults └── solutions │ └── smart_light │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── _static │ ├── p-redirect.png │ ├── p-se.png │ ├── p-sub.png │ ├── p-us.png │ ├── p1.png │ ├── p10.png │ ├── p11.png │ ├── p12.png │ ├── p13.png │ ├── p14.png │ ├── p15.png │ ├── p16.png │ ├── p17.png │ ├── p18.png │ ├── p19.png │ ├── p2.png │ ├── p20.png │ ├── p21.png │ ├── p22.jpg │ ├── p23.jpg │ ├── p24.jpg │ ├── p3.png │ ├── p4.png │ ├── p5.png │ ├── p6.png │ ├── p7.png │ ├── p8.png │ └── p9.png │ ├── components │ ├── factory_restore │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── component.mk │ │ ├── factory_restore.c │ │ └── factory_restore.h │ ├── lightbulb │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── lightbulb.c │ │ └── lightbulb.h │ └── linkkit_handle │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── linkkit_solo.c │ │ └── linkkit_solo.h │ ├── main │ ├── CMakeLists.txt │ ├── app_main.c │ └── component.mk │ ├── partitions_esp32.csv │ ├── partitions_esp32s2.csv │ ├── partitions_esp32s3.csv │ ├── partitions_esp8266.csv │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp32s2 │ ├── sdkconfig.defaults.esp32s3 │ ├── sdkconfig_esp32.defaults │ └── sdkconfig_esp8266.defaults ├── iotkit-embedded ├── certs │ └── root_ca.c ├── coap_cloud │ ├── Cloud_CoAPExport.h │ ├── Cloud_CoAPMessage.h │ ├── Cloud_CoAPNetwork.h │ ├── Cloud_CoAPPlatform.h │ ├── CoAPDeserialize.h │ ├── CoAPDeserialize_common.c │ ├── CoAPExport.c │ ├── CoAPMessage.c │ ├── CoAPMessage_common.c │ ├── CoAPNetwork.c │ ├── CoAPPlatform.h │ ├── CoAPSerialize.h │ ├── CoAPSerialize_common.c │ ├── coap_api.h │ ├── coap_wrapper.h │ ├── iotx_coap.h │ ├── iotx_coap_api.c │ ├── iotx_coap_config.h │ └── iotx_coap_internal.h ├── coap_server │ ├── CoAPPacket │ │ ├── CoAPDeserialize.h │ │ ├── CoAPDeserialize_common.c │ │ ├── CoAPMessage_common.c │ │ ├── CoAPPlatform.h │ │ ├── CoAPSerialize.h │ │ └── CoAPSerialize_common.c │ ├── coap_api.h │ ├── coap_wrapper.h │ ├── iotx_coap.h │ ├── iotx_coap_config.h │ ├── iotx_coap_internal.h │ └── server │ │ ├── CoAPExport.c │ │ ├── CoAPExport.h │ │ ├── CoAPInternal.h │ │ ├── CoAPMessage.c │ │ ├── CoAPMessage.h │ │ ├── CoAPNetwork.c │ │ ├── CoAPNetwork.h │ │ ├── CoAPObserve.c │ │ ├── CoAPObserve.h │ │ ├── CoAPPlatform.c │ │ ├── CoAPResource.c │ │ ├── CoAPResource.h │ │ ├── CoAPServer.c │ │ └── CoAPServer.h ├── dev_bind │ ├── dev_bind_api.h │ ├── dev_bind_wrapper.h │ └── impl │ │ ├── awss_bind.c │ │ ├── awss_bind_statis.c │ │ ├── awss_bind_statis.h │ │ ├── awss_cmp.h │ │ ├── awss_cmp_coap.c │ │ ├── awss_cmp_mqtt.c │ │ ├── awss_event.c │ │ ├── awss_event.h │ │ ├── awss_info.c │ │ ├── awss_info.h │ │ ├── awss_log.h │ │ ├── awss_notify.c │ │ ├── awss_notify.h │ │ ├── awss_packet.c │ │ ├── awss_packet.h │ │ ├── awss_report.c │ │ ├── awss_reset.h │ │ ├── awss_reset │ │ ├── awss_dev_reset.c │ │ └── awss_dev_reset_internal.h │ │ ├── awss_timer.c │ │ ├── awss_timer.h │ │ ├── awss_utils.h │ │ ├── dev_bind_internal.h │ │ ├── iot_import_awss.h │ │ ├── os │ │ ├── os.h │ │ └── os_misc.c │ │ ├── passwd.c │ │ ├── passwd.h │ │ ├── sha256.c │ │ └── sha256.h ├── dev_model │ ├── alcs_adapter.c │ ├── alcs_adapter.h │ ├── alcs_api.c │ ├── alcs_api.h │ ├── alcs_api_internal.h │ ├── alcs_base64.c │ ├── alcs_base64.h │ ├── alcs_client.c │ ├── alcs_coap.c │ ├── alcs_coap.h │ ├── alcs_internal.h │ ├── alcs_localsetup.c │ ├── alcs_localsetup.h │ ├── alcs_mqtt.c │ ├── alcs_mqtt.h │ ├── alcs_server.c │ ├── dev_model_api.h │ ├── dm_api.c │ ├── dm_client.c │ ├── dm_client.h │ ├── dm_client_adapter.c │ ├── dm_client_adapter.h │ ├── dm_cota.c │ ├── dm_cota.h │ ├── dm_fota.c │ ├── dm_fota.h │ ├── dm_intf.h │ ├── dm_ipc.c │ ├── dm_ipc.h │ ├── dm_log_report.c │ ├── dm_manager.c │ ├── dm_manager.h │ ├── dm_message.c │ ├── dm_message.h │ ├── dm_message_cache.c │ ├── dm_message_cache.h │ ├── dm_msg_process.c │ ├── dm_msg_process.h │ ├── dm_opt.c │ ├── dm_opt.h │ ├── dm_ota.c │ ├── dm_ota.h │ ├── dm_server.c │ ├── dm_server.h │ ├── dm_server_adapter.c │ ├── dm_server_adapter.h │ ├── dm_shadow.c │ ├── dm_shadow.h │ ├── dm_tsl_alink.c │ ├── dm_tsl_alink.h │ ├── dm_utils.c │ ├── dm_utils.h │ ├── dm_wrapper.h │ ├── impl_gateway.c │ ├── impl_gateway.h │ ├── impl_linkkit.c │ ├── impl_ntp.c │ ├── impl_ntp.h │ ├── impl_solo.c │ ├── impl_solo.h │ ├── iot_export_linkkit.h │ ├── iotx_alcs.h │ ├── iotx_alcs_config.h │ ├── iotx_cm.c │ ├── iotx_cm.h │ ├── iotx_cm_coap.c │ ├── iotx_cm_coap.h │ ├── iotx_cm_internal.h │ ├── iotx_cm_mqtt.c │ ├── iotx_cm_mqtt.h │ ├── iotx_dm.h │ ├── iotx_dm_config.h │ ├── iotx_dm_internal.h │ ├── iotx_log_report.h │ ├── linkkit_export.h │ └── linkkit_gateway_export.h ├── dev_reset │ ├── dev_reset.c │ ├── dev_reset_api.h │ ├── dev_reset_internal.h │ └── dev_reset_wrapper.h ├── dev_sign │ ├── dev_sign_api.h │ ├── dev_sign_config.h │ ├── dev_sign_internal.h │ ├── dev_sign_mqtt.c │ └── dev_sign_wrapper.h ├── dynamic_register │ ├── dynreg.c │ ├── dynreg_api.h │ ├── dynreg_internal.h │ └── dynreg_wrapper.h ├── http │ ├── http_api.h │ ├── http_debug.h │ ├── http_wrapper.h │ └── iotx_http_api.c ├── http2 │ ├── http2_api.c │ ├── http2_api.h │ ├── http2_config.h │ ├── http2_internal.h │ ├── http2_upload_api.c │ ├── http2_upload_api.h │ ├── http2_wrapper.h │ └── iotx_http2.c ├── infra │ ├── infra_cjson.c │ ├── infra_cjson.h │ ├── infra_compat.c │ ├── infra_compat.h │ ├── infra_config.h │ ├── infra_defs.c │ ├── infra_defs.h │ ├── infra_httpc.c │ ├── infra_httpc.h │ ├── infra_json_parser.c │ ├── infra_json_parser.h │ ├── infra_list.h │ ├── infra_log.c │ ├── infra_log.h │ ├── infra_md5.c │ ├── infra_md5.h │ ├── infra_net.c │ ├── infra_net.h │ ├── infra_preauth.c │ ├── infra_preauth.h │ ├── infra_prt_nwk_payload.c │ ├── infra_redirect_region.c │ ├── infra_redirect_region.h │ ├── infra_report.c │ ├── infra_report.h │ ├── infra_sha1.c │ ├── infra_sha1.h │ ├── infra_sha256.c │ ├── infra_sha256.h │ ├── infra_string.c │ ├── infra_string.h │ ├── infra_timer.c │ ├── infra_timer.h │ └── infra_types.h ├── mqtt │ ├── MQTTConnect.h │ ├── MQTTConnectClient.c │ ├── MQTTDeserializePublish.c │ ├── MQTTPacket.c │ ├── MQTTPacket.h │ ├── MQTTPublish.h │ ├── MQTTSerializePublish.c │ ├── MQTTSubscribe.h │ ├── MQTTSubscribeClient.c │ ├── MQTTUnsubscribe.h │ ├── MQTTUnsubscribeClient.c │ ├── iotx_mqtt_client.c │ ├── iotx_mqtt_client.h │ ├── iotx_mqtt_config.h │ ├── mqtt_api.c │ ├── mqtt_api.h │ ├── mqtt_internal.h │ └── mqtt_wrapper.h ├── ota │ ├── iotx_ota.c │ ├── iotx_ota.h │ ├── iotx_ota_config.h │ ├── iotx_ota_internal.h │ ├── ota_api.h │ ├── ota_coap.c │ ├── ota_fetch.c │ ├── ota_lib.c │ ├── ota_mqtt.c │ └── ota_wrapper.h └── wifi_provision │ ├── dev_ap │ ├── awss_dev_ap.c │ ├── awss_dev_ap.h │ └── dev_ap_wrapper.h │ ├── frameworks │ ├── aplist │ │ ├── awss_aplist.c │ │ └── awss_aplist.h │ ├── aws_lib.h │ ├── awss.c │ ├── awss_main.c │ ├── awss_main.h │ ├── awss_smartconfig.h │ ├── ieee80211 │ │ ├── zconfig_ieee80211.c │ │ └── zconfig_ieee80211.h │ ├── statics │ │ ├── awss_statis.c │ │ └── awss_statis.h │ ├── utils │ │ ├── awss_crypt.c │ │ ├── awss_crypt.h │ │ ├── zconfig_utils.c │ │ └── zconfig_utils.h │ ├── zconfig_lib.h │ ├── zconfig_protocol.c │ ├── zconfig_protocol.h │ └── zconfig_vendor_common.c │ ├── p2p │ ├── awss_wps.c │ ├── awss_wps.h │ └── p2p_wrapper.h │ ├── phone_ap │ ├── aha_wrapper.h │ ├── awss_aha.c │ ├── awss_aha.h │ ├── awss_wifimgr.c │ └── awss_wifimgr.h │ ├── router_ap │ ├── awss_adha.c │ └── awss_adha.h │ ├── smartconfig │ ├── awss_smartconfig.c │ └── smartconfig_wrapper.h │ ├── wifi_provision_api.h │ ├── wifi_provision_internal.h │ └── zero_config │ ├── awss_enrollee.c │ ├── awss_enrollee.h │ ├── awss_registrar.c │ └── zeroconfig_wrapper.h └── wrappers ├── external_libs ├── cJSON.c ├── cJSON.h └── nghttp2 │ ├── nghttp2.h │ ├── nghttp2_buf.c │ ├── nghttp2_buf.h │ ├── nghttp2_callbacks.c │ ├── nghttp2_callbacks.h │ ├── nghttp2_debug.c │ ├── nghttp2_debug.h │ ├── nghttp2_frame.c │ ├── nghttp2_frame.h │ ├── nghttp2_hd.c │ ├── nghttp2_hd.h │ ├── nghttp2_hd_huffman.c │ ├── nghttp2_hd_huffman.h │ ├── nghttp2_hd_huffman_data.c │ ├── nghttp2_helper.c │ ├── nghttp2_helper.h │ ├── nghttp2_http.c │ ├── nghttp2_http.h │ ├── nghttp2_int.h │ ├── nghttp2_map.c │ ├── nghttp2_map.h │ ├── nghttp2_mem.c │ ├── nghttp2_mem.h │ ├── nghttp2_net.c │ ├── nghttp2_net.h │ ├── nghttp2_npn.c │ ├── nghttp2_npn.h │ ├── nghttp2_option.c │ ├── nghttp2_option.h │ ├── nghttp2_outbound_item.c │ ├── nghttp2_outbound_item.h │ ├── nghttp2_pq.c │ ├── nghttp2_pq.h │ ├── nghttp2_priority_spec.c │ ├── nghttp2_priority_spec.h │ ├── nghttp2_queue.c │ ├── nghttp2_queue.h │ ├── nghttp2_rcbuf.c │ ├── nghttp2_rcbuf.h │ ├── nghttp2_session.c │ ├── nghttp2_session.h │ ├── nghttp2_stream.c │ ├── nghttp2_stream.h │ ├── nghttp2_submit.c │ ├── nghttp2_submit.h │ ├── nghttp2_version.c │ └── nghttp2ver.h ├── wrapper_awss.c ├── wrapper_crypto.c ├── wrapper_kv.c ├── wrapper_os.c ├── wrapper_ota.c ├── wrapper_product.c ├── wrapper_system.c ├── wrapper_tcp.c ├── wrapper_tls.c ├── wrapper_udp.c ├── wrapper_wifi.c └── wrappers_defs.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Config file 2 | .settings 3 | .project 4 | .cproject 5 | 6 | # IDF compile output 7 | examples/*/build/* 8 | examples/*/*/build/* 9 | 10 | # config 11 | sdkconfig 12 | sdkconfig.old 13 | 14 | # VS Code Settings 15 | .vscode/ 16 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_PRIV_INCLUDEDIRS 2 | iotkit-embedded/coap_server/CoAPPacket 3 | iotkit-embedded/coap_server/server 4 | iotkit-embedded/dev_bind/impl 5 | iotkit-embedded/dev_bind/impl/os 6 | iotkit-embedded/dev_bind/impl/awss_reset 7 | iotkit-embedded/wifi_provision/dev_ap 8 | iotkit-embedded/wifi_provision/frameworks 9 | iotkit-embedded/wifi_provision/frameworks/aplist 10 | iotkit-embedded/wifi_provision/frameworks/ieee80211 11 | iotkit-embedded/wifi_provision/frameworks/statics 12 | iotkit-embedded/wifi_provision/frameworks/utils 13 | iotkit-embedded/wifi_provision/p2p 14 | iotkit-embedded/wifi_provision/phone_ap 15 | iotkit-embedded/wifi_provision/router_ap 16 | iotkit-embedded/wifi_provision/smartconfig 17 | iotkit-embedded/wifi_provision/zero_config) 18 | 19 | set(COMPONENT_ADD_INCLUDEDIRS 20 | conn_mgr 21 | iotkit-embedded/coap_server 22 | iotkit-embedded/dev_bind 23 | iotkit-embedded/dev_model 24 | iotkit-embedded/dev_sign 25 | iotkit-embedded/dynamic_register 26 | iotkit-embedded/mqtt 27 | iotkit-embedded/ota 28 | iotkit-embedded/infra 29 | iotkit-embedded/wifi_provision 30 | iotkit-embedded 31 | wrappers) 32 | 33 | # Edit following two lines to set component requirements (see docs) 34 | set(COMPONENT_REQUIRES "nvs_flash" "app_update" "esp-tls") 35 | set(COMPONENT_PRIV_REQUIRES ) 36 | 37 | set(COMPONENT_SRCDIRS 38 | conn_mgr 39 | iotkit-embedded/certs 40 | iotkit-embedded/dev_bind/impl 41 | iotkit-embedded/dev_bind/impl/os 42 | iotkit-embedded/dev_bind/impl/awss_reset 43 | iotkit-embedded/dev_model 44 | iotkit-embedded/dev_reset 45 | iotkit-embedded/dev_sign 46 | iotkit-embedded/dynamic_register 47 | iotkit-embedded/infra 48 | iotkit-embedded/mqtt 49 | iotkit-embedded/ota 50 | iotkit-embedded/wifi_provision/dev_ap 51 | iotkit-embedded/wifi_provision/frameworks 52 | iotkit-embedded/wifi_provision/frameworks/aplist 53 | iotkit-embedded/wifi_provision/frameworks/ieee80211 54 | iotkit-embedded/wifi_provision/frameworks/statics 55 | iotkit-embedded/wifi_provision/frameworks/utils 56 | iotkit-embedded/wifi_provision/p2p 57 | iotkit-embedded/wifi_provision/phone_ap 58 | iotkit-embedded/wifi_provision/router_ap 59 | iotkit-embedded/wifi_provision/smartconfig 60 | iotkit-embedded/wifi_provision/zero_config 61 | iotkit-embedded/coap_server/CoAPPacket 62 | iotkit-embedded/coap_server/server 63 | wrappers) 64 | 65 | register_component() 66 | component_compile_options(-DAUTH_MODE_CERT) 67 | -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | # Makefile 2 | COMPONENT_ADD_LDFLAGS += -u ota_pubn_buf 3 | COMPONENT_PRIV_INCLUDEDIRS := \ 4 | iotkit-embedded/coap_server/CoAPPacket \ 5 | iotkit-embedded/coap_server/server \ 6 | iotkit-embedded/dev_bind/impl \ 7 | iotkit-embedded/dev_bind/impl/os \ 8 | iotkit-embedded/dev_bind/impl/awss_reset \ 9 | iotkit-embedded/wifi_provision/dev_ap \ 10 | iotkit-embedded/wifi_provision/frameworks \ 11 | iotkit-embedded/wifi_provision/frameworks/aplist \ 12 | iotkit-embedded/wifi_provision/frameworks/ieee80211 \ 13 | iotkit-embedded/wifi_provision/frameworks/statics \ 14 | iotkit-embedded/wifi_provision/frameworks/utils \ 15 | iotkit-embedded/wifi_provision/p2p \ 16 | iotkit-embedded/wifi_provision/phone_ap \ 17 | iotkit-embedded/wifi_provision/router_ap \ 18 | iotkit-embedded/wifi_provision/smartconfig \ 19 | iotkit-embedded/wifi_provision/zero_config 20 | 21 | COMPONENT_ADD_INCLUDEDIRS := \ 22 | conn_mgr \ 23 | iotkit-embedded/atm \ 24 | iotkit-embedded/coap_server \ 25 | iotkit-embedded/dev_bind \ 26 | iotkit-embedded/dev_model \ 27 | iotkit-embedded/dev_sign \ 28 | iotkit-embedded/dynamic_register \ 29 | iotkit-embedded/mqtt \ 30 | iotkit-embedded/ota \ 31 | iotkit-embedded/infra \ 32 | iotkit-embedded/wifi_provision \ 33 | iotkit-embedded \ 34 | wrappers 35 | 36 | COMPONENT_SRCDIRS := \ 37 | conn_mgr \ 38 | iotkit-embedded/atm \ 39 | iotkit-embedded/certs \ 40 | iotkit-embedded/dev_bind/impl \ 41 | iotkit-embedded/dev_bind/impl/os \ 42 | iotkit-embedded/dev_bind/impl/awss_reset \ 43 | iotkit-embedded/dev_model \ 44 | iotkit-embedded/dev_reset \ 45 | iotkit-embedded/dev_sign \ 46 | iotkit-embedded/dynamic_register \ 47 | iotkit-embedded/infra \ 48 | iotkit-embedded/mqtt \ 49 | iotkit-embedded/ota \ 50 | iotkit-embedded/wifi_provision/dev_ap \ 51 | iotkit-embedded/wifi_provision/frameworks \ 52 | iotkit-embedded/wifi_provision/frameworks/aplist \ 53 | iotkit-embedded/wifi_provision/frameworks/ieee80211 \ 54 | iotkit-embedded/wifi_provision/frameworks/statics \ 55 | iotkit-embedded/wifi_provision/frameworks/utils \ 56 | iotkit-embedded/wifi_provision/p2p \ 57 | iotkit-embedded/wifi_provision/phone_ap \ 58 | iotkit-embedded/wifi_provision/router_ap \ 59 | iotkit-embedded/wifi_provision/smartconfig \ 60 | iotkit-embedded/wifi_provision/zero_config \ 61 | iotkit-embedded/coap_server/CoAPPacket \ 62 | iotkit-embedded/coap_server/server \ 63 | wrappers 64 | 65 | CFLAGS += -Wno-char-subscripts 66 | -------------------------------------------------------------------------------- /config/mass_mfg/multipule_mfg_config.csv: -------------------------------------------------------------------------------- 1 | aliyun-key,namespace, 2 | DeviceName,data,string 3 | DeviceSecret,data,string 4 | ProductKey,data,string 5 | ProductSecret,data,string -------------------------------------------------------------------------------- /config/mass_mfg/multipule_mfg_values.csv: -------------------------------------------------------------------------------- 1 | id,DeviceName,DeviceSecret,ProductKey,ProductSecret 2 | 1,config,dsj3RuY74pgCBJ3zczKz1LaLK7RGApqh,a10BnLLzGv4,pVfLpS1u3A9JM0go 3 | 2,config,dsj3RuY74pgCBJ3zczKz1LaLK7RGApqh,a10BnLLzGv4,pVfLpS1u3A9JM0go 4 | 3,config,dsj3RuY74pgCBJ3zczKz1LaLK7RGApqh,a10BnLLzGv4,pVfLpS1u3A9JM0go -------------------------------------------------------------------------------- /config/mass_mfg/single_mfg_config.csv: -------------------------------------------------------------------------------- 1 | key,type,encoding,value 2 | aliyun-key,namespace,, 3 | DeviceName,data,string,config 4 | DeviceSecret,data,string,dsj3RuY74pgCBJ3zczKz1LaLK7RGApqh 5 | ProductKey,data,string,a10BnLLzGv4 6 | ProductSecret,data,string,pVfLpS1u3A9JM0go -------------------------------------------------------------------------------- /docs/_static/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/docs/_static/p1.png -------------------------------------------------------------------------------- /docs/_static/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/docs/_static/p2.png -------------------------------------------------------------------------------- /docs/_static/p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/docs/_static/p3.png -------------------------------------------------------------------------------- /docs/_static/p4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/docs/_static/p4.png -------------------------------------------------------------------------------- /docs/issue_template.md: -------------------------------------------------------------------------------- 1 | ----------------------------- 以下请删除 ----------------------------- 2 | 3 | 提交问题时,请先仔细阅读该段提示信息!! 4 | 5 | 为了更高效的解决 issue 中提交的问题,请按照以下 issue 模板进行提交,请注意以下信息: 6 | 1. 提交时请删除这段提示文字; 7 | 2. 提交时删除以下由 `//` 开头的文字,并对此做详细补充,如没有特殊信息,可写 `无`。 8 | 9 | 感谢配合。 10 | 11 | ----------------------------- 以上请删除 ----------------------------- 12 | 13 | ## 1. 开发环境 14 | 15 | - 模组或开发板: 16 | - esp-aliyun 版本(``git rev-parse --short HEAD`` 来获取 commit id): 17 | - ESP8266_RTOS_SDK 版本(``git rev-parse --short HEAD`` 来获取 commit id): 18 | - ESP-IDF 版本(``git rev-parse --short HEAD`` 来获取 commit id): 19 | 20 | ## 2. 问题描述 21 | 22 | // 请提供详细的问题描述。 23 | 24 | ### 2.1 复现步骤 25 | 26 | 1. ... 27 | 2. ... 28 | 29 | ### 2.2 复现问题的代码 30 | 31 | // 如果需要提交复现问题的代码, 可通过 [GIST](https://gist.github.com) 或通过附件的方式提交。 32 | 33 | ## 3. 调试 Logs 34 | 35 | // 由于 log 可能比较长,请通过附件的形式提供,否则该 issue 页面会非常长,不便于其他开发者查阅。 36 | 37 | ## 4. 其他项 38 | 39 | // 如果涉及到配网或其他兼容性问题,请提供具体手机型号、路由型号或其他信息。 -------------------------------------------------------------------------------- /examples/awss/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | set (EXTRA_COMPONENT_DIRS "../..") 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(awss) 12 | -------------------------------------------------------------------------------- /examples/awss/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | PROJECT_NAME := awss 6 | 7 | EXTRA_COMPONENT_DIRS := $(realpath ../../..) 8 | 9 | SDKCONFIG_DEFAULTS := sdkconfig_$(chip).defaults 10 | 11 | include $(IDF_PATH)/make/project.mk 12 | -------------------------------------------------------------------------------- /examples/awss/README.md: -------------------------------------------------------------------------------- 1 | # AWSS 解决方案 2 | 3 | ### 介绍 4 | `awss` 为客户提供配网解决方案. 设备可以通过阿里 <智能家居> APP 实现一键配网. 5 | 6 | ### 解决方案部署 7 | #### 1.参考 [README](../../README.md) 文档进行硬件准备、环境搭建、SDK 准备 8 | 9 | #### 2.阿里云平台部署 10 | 在 [智能生活开放平台](https://living.aliyun.com/#/) 创建产品, 参考[创建产品文档](https://living.aliyun.com/doc#readygo.html). 11 | > 配置较多, 如果不太懂, 也不用纠结, 后续都可以修改. 12 | > 如果已经创建过产品, 可跳过此步骤. 13 | 14 | 新增测试设备, 此处即可以获得`三元组`, 后续需要烧录到 NVS 分区. 15 | ![](_static/p2.png) 16 | 17 | 获取配网二维码, 后续设备配网中需扫描此二维码. 18 | ![](_static/p3.png) 19 | 20 | 21 | #### 3.下载本工程 22 | ``` 23 | git clone https://github.com/espressif/esp-aliyun.git 24 | cd esp-aliyun 25 | ``` 26 | 27 | #### 4.烧录三元组信息 28 | - 参考 [量产说明](../../config/mass_mfg/README.md) 文档烧录三元组 NVS 分区。 29 | 30 | > 如果重新配网, 请先执行 `make erase_flash`, 再烧录三元组. 31 | 32 | #### 5.编译 `awss` 并烧录运行 33 | ``` 34 | cd examples/awss 35 | make chip=esp32 defconfig 或者 make chip=esp8266 defconfig 36 | make -j8 flash monitor 37 | ``` 38 | 39 | #### 6.设备第一次运行时, 会进入配网 40 | 41 | ![](_static/p4.png) 42 | 43 | #### 7.手机从[阿里巴巴官网](https://living.aliyun.com/doc#muti-app.html) 下载`智能家居`公版 APP, 国内用户版. 44 | 45 | #### 8.注册好账号后,进入 APP, 右上角扫描, 扫描第二步的二维码配网. 46 | 设备端配网成功后会保存 `ssid` 和 `password` : 47 | ![](_static/p5.png) 48 | 49 | > 由于示例仅提供配网功能, 没有与云端建立 MQTT 链接, 因此 APP 上不会弹出配网成功页面, 会显示 `设备添加失败`. 如果需要添加设备, 可以运行 examples/solutions/smart_light 示例. -------------------------------------------------------------------------------- /examples/awss/_static/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/awss/_static/p1.png -------------------------------------------------------------------------------- /examples/awss/_static/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/awss/_static/p2.png -------------------------------------------------------------------------------- /examples/awss/_static/p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/awss/_static/p3.png -------------------------------------------------------------------------------- /examples/awss/_static/p4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/awss/_static/p4.png -------------------------------------------------------------------------------- /examples/awss/_static/p5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/awss/_static/p5.png -------------------------------------------------------------------------------- /examples/awss/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ".") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS ./app_main.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /examples/awss/main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/awss/main/component.mk -------------------------------------------------------------------------------- /examples/awss/partitions_esp32.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/awss/partitions_esp8266.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0xF0000 7 | fctry, data, nvs, 0x100000,0x4000 8 | ota_1, 0, ota_1, 0x110000,0xF0000 9 | -------------------------------------------------------------------------------- /examples/awss/sdkconfig_esp32.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | 3 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 4 | 5 | CONFIG_PARTITION_TABLE_CUSTOM=y 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32.csv" -------------------------------------------------------------------------------- /examples/awss/sdkconfig_esp8266.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y 2 | 3 | CONFIG_ENABLE_PTHREAD=y 4 | 5 | CONFIG_SSL_USING_WOLFSSL=y 6 | CONFIG_ESP_TLS_USING_WOLFSSL=y 7 | CONFIG_ESP_WOLFSSL_INTERNAL=y 8 | CONFIG_ESPTOOLPY_BAUD_921600B=y 9 | 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp8266.csv" -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | set (EXTRA_COMPONENT_DIRS "../../..") 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(mqtt_example) 12 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | PROJECT_NAME := mqtt_example 6 | 7 | EXTRA_COMPONENT_DIRS := $(realpath ../../..) 8 | 9 | SDKCONFIG_DEFAULTS := sdkconfig_$(chip).defaults 10 | 11 | include $(IDF_PATH)/make/project.mk 12 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/README.md: -------------------------------------------------------------------------------- 1 | # MQTT 解决方案 2 | 3 | ### 介绍 4 | `mqtt_example` 为客户提供连接阿里云, 演示发布和订阅功能. 5 | 6 | ### 解决方案部署 7 | #### 1.参考 [README](../../../README.md) 文档进行硬件准备、环境搭建、SDK 准备 8 | 9 | #### 2.阿里云平台部署 10 | 在阿里云 [物联网平台](https://iot.console.aliyun.com) 上创建产品. 产品 Topic 类列表如下: 11 | ![](_static/p5.png) 12 | 13 | 如果已在阿里云 [生活物联网平台](https://living.aliyun.com/#/) 创建产品, 会显示在 `物联网平台`, 但需要手动增加 Topic 类 `/${productKey}/${deviceName}/user/get` . 14 | ![](_static/p4.png) 15 | 16 | 修改 Topic `/${productKey}/${deviceName}/user/get` 的操作权限为 `发布和订阅`. 这样 MQTT 客户端可以收到自己发布的消息. 17 | ![](_static/p1.png) 18 | 19 | > 创建产品设备后,可以获取`三元组`, 后续需要烧录到 NVS 分区. 20 | 21 | #### 3.下载本工程 22 | ``` 23 | git clone https://github.com/espressif/esp-aliyun.git 24 | cd esp-aliyun 25 | ``` 26 | 27 | #### 4.烧录三元组信息 28 | - 参考 [量产说明](../../../config/mass_mfg/README.md) 文档烧录三元组 NVS 分区。 29 | 30 | > 如果执行了 `make erase_flash`, 需要重新烧录三元组. 31 | 32 | #### 5.编译 `mqtt_example` 并烧录运行 33 | ``` 34 | cd examples/mqtt/mqtt_example 35 | make chip=esp32 defconfig 或者 make chip=esp8266 defconfig 36 | make menuconfig 37 | ``` 38 | 39 | ![](_static/p2.png) 40 | 41 | - 配置烧写串口 42 | - 配置 `WIFI_SSID`, `WIFI_PASSWORD` 43 | 44 | ``` 45 | make -j8 flash monitor 46 | ``` 47 | 48 | #### 6.设备运行 49 | 50 | 设备连接 WIFI 之后, 进行 MQTT 连接, 订阅和发布消息. 订阅和发布的 Topic 都是 `/${productKey}/${deviceName}/user/get` , 因此设备会收到自己发送的消息. 51 | ![](_static/p3.png) 52 | 53 | 54 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/_static/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/mqtt/mqtt_example/_static/p1.png -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/_static/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/mqtt/mqtt_example/_static/p2.png -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/_static/p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/mqtt/mqtt_example/_static/p3.png -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/_static/p4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/mqtt/mqtt_example/_static/p4.png -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/_static/p5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/mqtt/mqtt_example/_static/p5.png -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/components/mqtt_handle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "mqtt_solo.c") 4 | 5 | set(COMPONENT_REQUIRES "esp-aliyun") 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/components/mqtt_handle/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/components/mqtt_handle/mqtt_solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _MQTT_SOLO_H__ 25 | #define _MQTT_SOLO_H__ 26 | 27 | int mqtt_main(void *paras); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ".") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS ./app_main.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "myssid" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | 15 | Can be left blank if the network has no security set. 16 | 17 | endmenu 18 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/mqtt/mqtt_example/main/component.mk -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/partitions_esp32.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/partitions_esp8266.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0xF0000 7 | fctry, data, nvs, 0x100000,0x4000 8 | ota_1, 0, ota_1, 0x110000,0xF0000 9 | -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/sdkconfig_esp32.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | 3 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 4 | 5 | CONFIG_PARTITION_TABLE_CUSTOM=y 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32.csv" -------------------------------------------------------------------------------- /examples/mqtt/mqtt_example/sdkconfig_esp8266.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y 2 | 3 | CONFIG_ENABLE_PTHREAD=y 4 | 5 | CONFIG_SSL_USING_WOLFSSL=y 6 | CONFIG_ESP_TLS_USING_WOLFSSL=y 7 | CONFIG_ESP_WOLFSSL_INTERNAL=y 8 | CONFIG_ESPTOOLPY_BAUD_921600B=y 9 | 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp8266.csv" -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | set (EXTRA_COMPONENT_DIRS "../../..") 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(ota_example_mqtt) 12 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | PROJECT_NAME := ota_example_mqtt 6 | 7 | EXTRA_COMPONENT_DIRS := $(realpath ../../..) 8 | 9 | SDKCONFIG_DEFAULTS := sdkconfig_$(chip).defaults 10 | 11 | include $(IDF_PATH)/make/project.mk 12 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/README.md: -------------------------------------------------------------------------------- 1 | # OTA 解决方案 2 | 3 | ### 介绍 4 | `ota_example_mqtt` 为客户提供连接阿里云, 云端通过 MQTT 协议下发升级指令, 进行升级固件的示例. 5 | 6 | ### 解决方案部署 7 | #### 1.参考 [README](../../../README.md) 文档进行硬件准备、环境搭建、SDK 准备 8 | 9 | #### 2.阿里云平台部署 10 | 在阿里云 [物联网平台](https://iot.console.aliyun.com) 创建产品. 或者在阿里云 [生活物联网平台](https://living.aliyun.com/#/) 创建产品, 会显示在 `物联网平台`, 参考[创建产品文档](https://living.aliyun.com/doc#readygo.html). 11 | > 如果已经创建过产品, 可跳过此步骤. 12 | > 创建产品设备后,可以获取`三元组`, 后续需要烧录到 NVS 分区. 13 | 14 | #### 3.下载本工程 15 | ``` 16 | git clone https://github.com/espressif/esp-aliyun.git 17 | cd esp-aliyun 18 | ``` 19 | 20 | #### 4.烧录三元组信息 21 | - 参考 [量产说明](../../../config/mass_mfg/README.md) 文档烧录三元组 NVS 分区. 22 | 23 | > 如果执行了 `make erase_flash`, 需要重新烧录三元组. 24 | 25 | #### 5.编译 `ota_example_mqtt` 并烧录运行 26 | ``` 27 | cd examples/ota/ota_example_mqtt 28 | make chip=esp32 defconfig 或者 make chip=esp8266 defconfig 29 | make menuconfig 30 | ``` 31 | 32 | ![](_static/p1.png) 33 | 34 | - 配置烧写串口 35 | - 配置 `WIFI_SSID`, `WIFI_PASSWORD` 36 | 37 | ``` 38 | make -j8 flash monitor 39 | ``` 40 | 41 | #### 6.设备运行 42 | 43 | 设备建立 MQTT 连接之后等待升级. 44 | > 设备需要上报固件版本号, 才能响应升级指令. 45 | 46 | ![](_static/p2.png) 47 | 48 | 在[管理控制台](https://iot.console.aliyun.com/ota/list)上传固件, 验证固件后, 下发升级指令. 49 | > 上传固件版本号需要和当前版本号不同. 50 | > 上传固件版本名称与实际固件版本保持一致. 51 | 52 | ![](_static/p3.png) 53 | 54 | 设备端收到升级指令后, 即开始 OTA: 55 | ![](_static/p4.png) 56 | 57 | 升级完成后, 会检查固件的有效性, 在固件有效时,立即重启运行新固件: 58 | ![](_static/p5.png) 59 | ![](_static/p6.png) 60 | 61 | 上报版本号和固件版本名称一致时, 管理控制台显示升级成功. -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/_static/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/_static/p1.png -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/_static/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/_static/p2.png -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/_static/p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/_static/p3.png -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/_static/p4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/_static/p4.png -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/_static/p5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/_static/p5.png -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/_static/p6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/_static/p6.png -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/components/ota_handle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "ota_solo.c") 4 | 5 | set(COMPONENT_REQUIRES "esp-aliyun") 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/components/ota_handle/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/components/ota_handle/ota_solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _OTA_SOLO_H__ 25 | #define _OTA_SOLO_H__ 26 | 27 | int ota_main(void *paras); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ".") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS ./app_main.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "myssid" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | 15 | Can be left blank if the network has no security set. 16 | 17 | endmenu 18 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/ota/ota_example_mqtt/main/component.mk -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/partitions_esp32.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/partitions_esp8266.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0xF0000 7 | fctry, data, nvs, 0x100000,0x4000 8 | ota_1, 0, ota_1, 0x110000,0xF0000 9 | -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/sdkconfig_esp32.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | 3 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 4 | 5 | CONFIG_PARTITION_TABLE_CUSTOM=y 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32.csv" -------------------------------------------------------------------------------- /examples/ota/ota_example_mqtt/sdkconfig_esp8266.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y 2 | 3 | CONFIG_ENABLE_PTHREAD=y 4 | 5 | CONFIG_SSL_USING_WOLFSSL=y 6 | CONFIG_ESP_TLS_USING_WOLFSSL=y 7 | CONFIG_ESP_WOLFSSL_INTERNAL=y 8 | CONFIG_ESPTOOLPY_BAUD_921600B=y 9 | 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp8266.csv" -------------------------------------------------------------------------------- /examples/solo/example_solo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | set (EXTRA_COMPONENT_DIRS "../../..") 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(example_solo) 12 | -------------------------------------------------------------------------------- /examples/solo/example_solo/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | PROJECT_NAME := example_solo 6 | 7 | EXTRA_COMPONENT_DIRS := $(realpath ../../..) 8 | 9 | SDKCONFIG_DEFAULTS := sdkconfig_$(chip).defaults 10 | 11 | include $(IDF_PATH)/make/project.mk -------------------------------------------------------------------------------- /examples/solo/example_solo/components/databases/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "app_entry.c") 4 | 5 | set(COMPONENT_REQUIRES "transports") 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/databases/app_entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _APP_ENTRY_H__ 25 | #define _APP_ENTRY_H__ 26 | 27 | #include "stdint.h" 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #ifdef CONFIG_IDF_TARGET_ESP8266 33 | #define CONN_MGR_TASK_SIZE 3 * 1024 34 | #else 35 | #define CONN_MGR_TASK_SIZE 6 * 1024 36 | #endif 37 | 38 | void app_get_input_param(char *param, size_t param_len); 39 | int app_check_config_pk(void); 40 | void start_conn_mgr(void);; 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/databases/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/linkkit_handle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "linkkit_solo.c") 4 | 5 | set(COMPONENT_REQUIRES "esp-aliyun" "transports" "json") 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/linkkit_handle/Kconfig: -------------------------------------------------------------------------------- 1 | menu "iotkit solo" 2 | config SUPPORT_RAW_DATA 3 | bool "Support raw data transfere" 4 | default n 5 | help 6 | Select this option to enable raw data transfere 7 | endmenu 8 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/linkkit_handle/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/linkkit_handle/linkkit_solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _LINKKIT_SOLO_H__ 25 | #define _LINKKIT_SOLO_H__ 26 | 27 | void linkkit_main(void *paras); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/transports/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "transport_uart.c") 4 | 5 | set(COMPONENT_REQUIRES "esp-aliyun") 6 | set(COMPONENT_PRIV_REQUIRES "databases") 7 | register_component() -------------------------------------------------------------------------------- /examples/solo/example_solo/components/transports/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/transports/transport_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _TRANSPORT_DATA_H__ 25 | #define _TRANSPORT_DATA_H__ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef enum { 32 | HOST_TRANSPORT_UNKNOWN = 0x00, /** Unknown. Default uninitialized value */ 33 | HOST_TRANSPORT_UART = 0x01, /** HOST over Uart */ 34 | HOST_TRANSPORT_ETHERNET = 0x02, 35 | } host_transport_t; 36 | 37 | int host_transport_handle(const uint8_t *data, size_t data_len); 38 | int host_transport_init(host_transport_t method); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /examples/solo/example_solo/components/transports/transport_uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _TRANSPORT_UART_H__ 25 | #define _TRANSPORT_UART_H__ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #define TRANSPORT_UART_RECV_BUF_SIZE 256 32 | #define TRANSPORT_UART_QUEUE_SIZE 1 33 | 34 | int transport_uart_write_bytes(const void *data, size_t data_size); 35 | int transport_uart_handle_init(void); 36 | void transport_uart_task_create(void); 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /examples/solo/example_solo/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ".") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES "transports" "databases" "linkkit_handle") 6 | 7 | set(COMPONENT_SRCS ./app_main.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /examples/solo/example_solo/main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solo/example_solo/main/component.mk -------------------------------------------------------------------------------- /examples/solo/example_solo/partitions_esp32.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/solo/example_solo/partitions_esp32s2.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/solo/example_solo/partitions_esp32s3.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/solo/example_solo/partitions_esp8266.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0xF0000 7 | fctry, data, nvs, 0x100000,0x4000 8 | ota_1, 0, ota_1, 0x110000,0xF0000 9 | -------------------------------------------------------------------------------- /examples/solo/example_solo/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | CONFIG_AWSS_CHANNELSCAN_INTERVAL_MS=100 3 | CONFIG_SNTP_RETRY_TIMEOUT=500 4 | CONFIG_SNTP_RETRY_MAX=20 5 | CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=3 6 | CONFIG_AWSS_TIMEOUT_INTERVAL_MS=60000 7 | CONFIG_TIMER_TASK_STACK_DEPTH=3072 8 | CONFIG_TCP_SYNMAXRTX=3 9 | -------------------------------------------------------------------------------- /examples/solo/example_solo/sdkconfig.defaults.esp32s2: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 2 | CONFIG_PARTITION_TABLE_CUSTOM=y 3 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32s2.csv" 4 | -------------------------------------------------------------------------------- /examples/solo/example_solo/sdkconfig.defaults.esp32s3: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 2 | CONFIG_PARTITION_TABLE_CUSTOM=y 3 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32s3.csv" 4 | -------------------------------------------------------------------------------- /examples/solo/example_solo/sdkconfig_esp32.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | CONFIG_AWSS_CHANNELSCAN_INTERVAL_MS=100 3 | CONFIG_SNTP_RETRY_TIMEOUT=500 4 | CONFIG_SNTP_RETRY_MAX=20 5 | CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=3 6 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 7 | CONFIG_AWSS_TIMEOUT_INTERVAL_MS=60000 8 | CONFIG_TIMER_TASK_STACK_DEPTH=3072 9 | CONFIG_TCP_SYNMAXRTX=3 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32.csv" 12 | -------------------------------------------------------------------------------- /examples/solo/example_solo/sdkconfig_esp8266.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y 2 | CONFIG_ENABLE_PTHREAD=y 3 | CONFIG_ESPTOOLPY_BAUD_921600B=y 4 | CONFIG_AWSS_TIMEOUT_INTERVAL_MS=60000 5 | CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=6144 6 | CONFIG_TCP_SYNMAXRTX=3 7 | CONFIG_FREERTOS_TIMER_STACKSIZE=3072 8 | CONFIG_AWSS_CHANNELSCAN_INTERVAL_MS=100 9 | CONFIG_SNTP_RETRY_TIMEOUT=500 10 | CONFIG_SNTP_RETRY_MAX=20 11 | CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=3 12 | CONFIG_TCP_HIGH_SPEED_RETRANSMISSION=y 13 | CONFIG_PARTITION_TABLE_CUSTOM=y 14 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp8266.csv" 15 | CONFIG_SUPPORT_TCP=y 16 | CONFIG_MBEDTLS_DYNAMIC_BUFFER=y 17 | CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y 18 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | set (EXTRA_COMPONENT_DIRS "../../..") 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(smart_light) 12 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | PROJECT_NAME := smart_light 6 | 7 | EXTRA_COMPONENT_DIRS := $(realpath ../../..) 8 | 9 | SDKCONFIG_DEFAULTS := sdkconfig_$(chip).defaults 10 | 11 | include $(IDF_PATH)/make/project.mk -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p-redirect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p-redirect.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p-se.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p-se.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p-sub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p-sub.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p-us.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p-us.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p1.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p10.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p11.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p12.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p13.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p14.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p15.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p16.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p17.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p18.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p19.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p2.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p20.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p21.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p22.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p22.jpg -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p23.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p23.jpg -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p24.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p24.jpg -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p3.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p4.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p5.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p6.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p7.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p8.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/_static/p9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/_static/p9.png -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/factory_restore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "factory_restore.c") 4 | 5 | set(COMPONENT_REQUIRES "esp-aliyun") 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/factory_restore/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "[Aliyun]Factory restore" 2 | 3 | config FACTORY_QUICK_REBOOT_TIMEOUT 4 | int "Quick reboot timeout, unit second" 5 | default 6 6 | help 7 | Timeout for exiting quick reboot timer, users should reboot device before this timeout. 8 | 9 | config FACTORY_QUICK_REBOOT_MAX_TIMES 10 | int "Quick reboot times max record" 11 | default 5 12 | help 13 | If quick reboot times reach this max value, device will do factory restore. 14 | 15 | endmenu 16 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/factory_restore/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/factory_restore/factory_restore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2018 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "esp_err.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /** 34 | * @brief Initialize factory restore 35 | * 36 | * @note For some devices which don't have a physical restore key or button, such as light, we use 37 | * a quick reboot method to record the reboot times, if users quickly reboot the device within 38 | * a specific time, configured by FACTORY_QUICK_REBOOT_TIMEOUT, and reboot several times, 39 | * configured by FACTORY_QUICK_REBOOT_MAX_TIMES, the device will do a factory restore, clear 40 | * stored ssid and password. 41 | * 42 | * @return 43 | * - ESP_OK : OK 44 | * - others : fail 45 | */ 46 | esp_err_t factory_restore_init(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/lightbulb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "lightbulb.c") 4 | 5 | set(COMPONENT_REQUIRES) 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/lightbulb/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/linkkit_handle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | set(COMPONENT_SRCS "linkkit_solo.c") 4 | 5 | set(COMPONENT_REQUIRES "esp-aliyun" "json" "lightbulb") 6 | 7 | register_component() 8 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/linkkit_handle/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./ 2 | COMPONENT_SRCDIRS := ./ 3 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/components/linkkit_handle/linkkit_solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _LINKKIT_SOLO_H__ 25 | #define _LINKKIT_SOLO_H__ 26 | 27 | void linkkit_main(void *paras); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ".") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS ./app_main.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-aliyun/dffa31951f7c8fff33963308ded0f09a9e21618d/examples/solutions/smart_light/main/component.mk -------------------------------------------------------------------------------- /examples/solutions/smart_light/partitions_esp32.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/partitions_esp32s2.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/partitions_esp32s3.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, , 0x4000, 4 | otadata, data, ota, , 0x2000, 5 | phy_init, data, phy, , 0x1000, 6 | ota_0, app, ota_0, , 1M, 7 | ota_1, app, ota_1, , 1M, 8 | fctry, data, nvs, , 0x4000 9 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/partitions_esp8266.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0xF0000 7 | fctry, data, nvs, 0x100000,0x4000 8 | ota_1, 0, ota_1, 0x110000,0xF0000 9 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | CONFIG_TIMER_TASK_STACK_DEPTH=3072 3 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/sdkconfig.defaults.esp32s2: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 2 | CONFIG_PARTITION_TABLE_CUSTOM=y 3 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32s2.csv" 4 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/sdkconfig.defaults.esp32s3: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 2 | CONFIG_PARTITION_TABLE_CUSTOM=y 3 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32s3.csv" 4 | -------------------------------------------------------------------------------- /examples/solutions/smart_light/sdkconfig_esp32.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_BAUD_921600B=y 2 | 3 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 4 | 5 | CONFIG_TIMER_TASK_STACK_DEPTH=3072 6 | 7 | CONFIG_PARTITION_TABLE_CUSTOM=y 8 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32.csv" -------------------------------------------------------------------------------- /examples/solutions/smart_light/sdkconfig_esp8266.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y 2 | CONFIG_ENABLE_PTHREAD=y 3 | CONFIG_ESPTOOLPY_BAUD_921600B=y 4 | CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=6144 5 | CONFIG_FREERTOS_TIMER_STACKSIZE=3072 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp8266.csv" 8 | CONFIG_SUPPORT_TCP=y 9 | CONFIG_MBEDTLS_DYNAMIC_BUFFER=y 10 | CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y 11 | -------------------------------------------------------------------------------- /iotkit-embedded/certs/root_ca.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | 7 | const char *iotx_ca_crt = \ 8 | { 9 | \ 10 | "-----BEGIN CERTIFICATE-----\r\n" 11 | "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\r\n" \ 12 | "A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\r\n" \ 13 | "b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\r\n" \ 14 | "MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\r\n" \ 15 | "YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT\r\n" \ 16 | "aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ\r\n" \ 17 | "jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp\r\n" \ 18 | "xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp\r\n" \ 19 | "1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG\r\n" \ 20 | "snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ\r\n" \ 21 | "U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8\r\n" \ 22 | "9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E\r\n" \ 23 | "BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B\r\n" \ 24 | "AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz\r\n" \ 25 | "yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE\r\n" \ 26 | "38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP\r\n" \ 27 | "AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad\r\n" \ 28 | "DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME\r\n" \ 29 | "HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==\r\n" \ 30 | "-----END CERTIFICATE-----" 31 | }; 32 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/Cloud_CoAPExport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "Cloud_CoAPNetwork.h" 6 | #include "iotx_coap_internal.h" 7 | 8 | #ifndef CLOUD__COAP_EXPORT_H__ 9 | #define CLOUD__COAP_EXPORT_H__ 10 | 11 | /* #define COAP_DTLS_SUPPORT */ 12 | typedef CoAPMsgOption Cloud_CoAPMsgOption; 13 | typedef CoAPMessageCode Cloud_CoAPMessageCode; 14 | typedef CoAPMessage Cloud_CoAPMessage ; 15 | #define COAP_OPTION_SEQ 2089 16 | 17 | typedef void (*Cloud_CoAPRespMsgHandler)(void *data, void *message); 18 | 19 | typedef struct { 20 | void *user; 21 | unsigned short msgid; 22 | char acked; 23 | unsigned char tokenlen; 24 | unsigned char token[8]; 25 | unsigned char retrans_count; 26 | unsigned short timeout; 27 | unsigned short timeout_val; 28 | unsigned char *message; 29 | unsigned int msglen; 30 | Cloud_CoAPRespMsgHandler resp; 31 | struct list_head sendlist; 32 | } Cloud_CoAPSendNode; 33 | 34 | 35 | typedef struct { 36 | unsigned char count; 37 | unsigned char maxcount; 38 | struct list_head sendlist; 39 | } Cloud_CoAPSendList; 40 | 41 | 42 | typedef void (*Cloud_CoAPEventNotifier)(unsigned int event, void *p_message); 43 | typedef struct { 44 | char *url; 45 | unsigned char maxcount; /*list maximal count*/ 46 | unsigned int waittime; 47 | Cloud_CoAPEventNotifier notifier; 48 | } Cloud_CoAPInitParam; 49 | 50 | typedef struct { 51 | unsigned short message_id; 52 | coap_network_t network; 53 | Cloud_CoAPEventNotifier notifier; 54 | unsigned char *sendbuf; 55 | unsigned char *recvbuf; 56 | Cloud_CoAPSendList list; 57 | unsigned int waittime; 58 | } Cloud_CoAPContext; 59 | 60 | #define COAP_TRC(...) log_debug("coap_cloud", __VA_ARGS__) 61 | #define COAP_DUMP(...) log_debug("coap_cloud", __VA_ARGS__) 62 | #define COAP_DEBUG(...) log_debug("coap_cloud", __VA_ARGS__) 63 | #define COAP_INFO(...) log_info("coap_cloud", __VA_ARGS__) 64 | #define COAP_WRN(...) log_warning("coap_cloud", __VA_ARGS__) 65 | #define COAP_ERR(...) log_err("coap_cloud", __VA_ARGS__) 66 | 67 | Cloud_CoAPContext *Cloud_CoAPContext_create(Cloud_CoAPInitParam *param); 68 | void Cloud_CoAPContext_free(Cloud_CoAPContext *p_ctx); 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/Cloud_CoAPMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #include "Cloud_CoAPExport.h" 9 | 10 | #ifndef __COAP_HANDLE_MSG_H__ 11 | #define __COAP_HANDLE_MSG_H__ 12 | 13 | int Cloud_CoAPStrOption_add(Cloud_CoAPMessage *message, unsigned short optnum, 14 | unsigned char *data, unsigned short datalen); 15 | 16 | 17 | int Cloud_CoAPUintOption_add(Cloud_CoAPMessage *message, unsigned short optnum, 18 | unsigned int data); 19 | 20 | unsigned short Cloud_CoAPMessageId_gen(Cloud_CoAPContext *context); 21 | 22 | int Cloud_CoAPMessageId_set(Cloud_CoAPMessage *message, unsigned short msgid); 23 | 24 | int Cloud_CoAPMessageType_set(Cloud_CoAPMessage *message, unsigned char type); 25 | 26 | int Cloud_CoAPMessageCode_set(Cloud_CoAPMessage *message, Cloud_CoAPMessageCode code); 27 | 28 | int Cloud_CoAPMessageToken_set(Cloud_CoAPMessage *message, unsigned char *token, 29 | unsigned char tokenlen); 30 | 31 | int Cloud_CoAPMessageUserData_set(Cloud_CoAPMessage *message, void *userdata); 32 | 33 | int Cloud_CoAPMessagePayload_set(Cloud_CoAPMessage *message, unsigned char *payload, 34 | unsigned short payloadlen); 35 | 36 | int Cloud_CoAPMessageHandler_set(Cloud_CoAPMessage *message, Cloud_CoAPRespMsgHandler handler); 37 | 38 | int Cloud_CoAPMessage_init(Cloud_CoAPMessage *message); 39 | 40 | int Cloud_CoAPMessage_destory(Cloud_CoAPMessage *message); 41 | 42 | int Cloud_CoAPMessage_send(Cloud_CoAPContext *context, Cloud_CoAPMessage *message); 43 | 44 | int Cloud_CoAPMessage_recv(Cloud_CoAPContext *context, unsigned int timeout, int readcount); 45 | 46 | int Cloud_CoAPMessage_cycle(Cloud_CoAPContext *context); 47 | 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/Cloud_CoAPNetwork.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | 7 | #ifndef COAP_TRANSPORT_H__ 8 | #define COAP_TRANSPORT_H__ 9 | 10 | typedef enum { 11 | COAP_ENDPOINT_NOSEC = 0, 12 | COAP_ENDPOINT_DTLS, 13 | COAP_ENDPOINT_PSK, 14 | } coap_endpoint_type; 15 | 16 | 17 | typedef struct { 18 | DTLSContext *context; 19 | } coap_remote_session_t; 20 | 21 | 22 | typedef struct { 23 | int socket_id; 24 | coap_endpoint_type ep_type; 25 | void *context; 26 | } coap_network_t; 27 | 28 | 29 | typedef struct { 30 | coap_endpoint_type ep_type; 31 | unsigned char *p_ca_cert_pem; 32 | char *p_host; 33 | unsigned short port; 34 | } coap_network_init_t; 35 | 36 | 37 | unsigned int Cloud_CoAPNetwork_init(const coap_network_init_t *p_param, coap_network_t *p_network); 38 | 39 | 40 | unsigned int Cloud_CoAPNetwork_write(coap_network_t *p_network, 41 | const unsigned char *p_data, 42 | unsigned int datalen); 43 | 44 | int Cloud_CoAPNetwork_read(coap_network_t *network, unsigned char *data, 45 | unsigned int datalen, unsigned int timeout); 46 | 47 | unsigned int Cloud_CoAPNetwork_deinit(coap_network_t *p_network); 48 | 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/Cloud_CoAPPlatform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __COAP_PLATFORM_OS_H__ 6 | #define __COAP_PLATFORM_OS_H__ 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif /* __cplusplus */ 12 | 13 | #ifdef INFRA_MEM_STATS 14 | #include "infra_mem_stats.h" 15 | #define coap_malloc(size) LITE_malloc(size, MEM_MAGIC, "coap.cloud") 16 | #define coap_free(ptr) LITE_free(ptr) 17 | #else 18 | #define coap_malloc(size) HAL_Malloc(size) 19 | #define coap_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 20 | #endif 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif /* __cplusplus */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/CoAPDeserialize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef __COAP_DESERIALIZE_H__ 8 | #define __COAP_DESERIALIZE_H__ 9 | #include 10 | #include "iotx_coap_internal.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif /* __cplusplus */ 15 | 16 | int CoAPDeserialize_Message(CoAPMessage *msg, unsigned char *buf, int buflen); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif /* __cplusplus */ 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/CoAPPlatform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __COAP_PLATFORM_OS_H__ 6 | #define __COAP_PLATFORM_OS_H__ 7 | 8 | #include 9 | #include "iotx_coap_internal.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | #ifdef INFRA_MEM_STATS 16 | #include "infra_mem_stats.h" 17 | #define coap_malloc(size) LITE_malloc(size, MEM_MAGIC, "coap.local") 18 | #define coap_free(ptr) LITE_free(ptr) 19 | #else 20 | #define coap_malloc(size) HAL_Malloc(size) 21 | #define coap_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 22 | #endif 23 | 24 | #ifdef INFRA_LOG 25 | #include "infra_log.h" 26 | #define COAP_ERR(...) log_err("coap_local", __VA_ARGS__) 27 | #define COAP_WRN(...) log_warning("coap_local", __VA_ARGS__) 28 | #define COAP_INFO(...) log_info("coap_local", __VA_ARGS__) 29 | #define COAP_TRC(...) log_debug("coap_local", __VA_ARGS__) 30 | #define COAP_DUMP(...) log_debug("coap_local", __VA_ARGS__) 31 | #define COAP_DEBUG(...) log_debug("coap_local", __VA_ARGS__) 32 | #define COAP_FLOW(...) log_flow("coap_local", __VA_ARGS__) 33 | #else 34 | #define COAP_ERR(...) 35 | #define COAP_WRN(...) 36 | #define COAP_INFO(...) 37 | #define COAP_TRC(...) 38 | #define COAP_DUMP(...) 39 | #define COAP_DEBUG(...) 40 | #define COAP_FLOW(...) 41 | #endif 42 | 43 | int platform_is_multicast(const char *ip_str); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif /* __cplusplus */ 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/CoAPSerialize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef __COAP_SERIALIZE_H__ 8 | #define __COAP_SERIALIZE_H__ 9 | #include "iotx_coap_internal.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | unsigned short CoAPSerialize_MessageLength(CoAPMessage *msg); 16 | 17 | int CoAPSerialize_Message(CoAPMessage *msg, unsigned char *buf, unsigned short buflen); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif /* __cplusplus */ 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/iotx_coap.h: -------------------------------------------------------------------------------- 1 | #include "CoAPServer.h" 2 | #include "iotx_coap_internal.h" 3 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_cloud/iotx_coap_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __IOTX_COAP_CONFIG__ 2 | #define __IOTX_COAP_CONFIG__ 3 | 4 | #define COAP_MSG_MAX_TOKEN_LEN 8 5 | #define COAP_MSG_MAX_OPTION_NUM 12 6 | #define COAP_MSG_MAX_PATH_LEN 128 7 | #ifndef COAP_LARGE_MEMORY_SUPPORT 8 | #define COAP_MSG_MAX_PDU_LEN 1280 9 | #else 10 | #define COAP_MSG_MAX_PDU_LEN 4096 11 | #endif 12 | 13 | #ifndef CONFIG_COAP_AUTH_TIMEOUT 14 | #define CONFIG_COAP_AUTH_TIMEOUT (3 * 1000) 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/CoAPPacket/CoAPDeserialize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef __COAP_DESERIALIZE_H__ 8 | #define __COAP_DESERIALIZE_H__ 9 | #include 10 | #include "iotx_coap_internal.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif /* __cplusplus */ 15 | 16 | int CoAPDeserialize_Message(CoAPMessage *msg, unsigned char *buf, int buflen); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif /* __cplusplus */ 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/CoAPPacket/CoAPPlatform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __COAP_PLATFORM_OS_H__ 6 | #define __COAP_PLATFORM_OS_H__ 7 | 8 | #include 9 | #include "iotx_coap_internal.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | #ifdef INFRA_MEM_STATS 16 | #include "infra_mem_stats.h" 17 | #define coap_malloc(size) LITE_malloc(size, MEM_MAGIC, "coap.local") 18 | #define coap_free(ptr) LITE_free(ptr) 19 | #else 20 | #define coap_malloc(size) HAL_Malloc(size) 21 | #define coap_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 22 | #endif 23 | 24 | #ifdef INFRA_LOG 25 | #include "infra_log.h" 26 | #define COAP_ERR(...) log_err("coap_local", __VA_ARGS__) 27 | #define COAP_WRN(...) log_warning("coap_local", __VA_ARGS__) 28 | #define COAP_INFO(...) log_info("coap_local", __VA_ARGS__) 29 | #define COAP_TRC(...) log_debug("coap_local", __VA_ARGS__) 30 | #define COAP_DUMP(...) log_debug("coap_local", __VA_ARGS__) 31 | #define COAP_DEBUG(...) log_debug("coap_local", __VA_ARGS__) 32 | #define COAP_FLOW(...) log_flow("coap_local", __VA_ARGS__) 33 | #else 34 | #define COAP_ERR(...) 35 | #define COAP_WRN(...) 36 | #define COAP_INFO(...) 37 | #define COAP_TRC(...) 38 | #define COAP_DUMP(...) 39 | #define COAP_DEBUG(...) 40 | #define COAP_FLOW(...) 41 | #endif 42 | 43 | int platform_is_multicast(const char *ip_str); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif /* __cplusplus */ 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/CoAPPacket/CoAPSerialize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef __COAP_SERIALIZE_H__ 8 | #define __COAP_SERIALIZE_H__ 9 | #include "iotx_coap_internal.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | unsigned short CoAPSerialize_MessageLength(CoAPMessage *msg); 16 | 17 | int CoAPSerialize_Message(CoAPMessage *msg, unsigned char *buf, unsigned short buflen); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif /* __cplusplus */ 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/iotx_coap.h: -------------------------------------------------------------------------------- 1 | #include "CoAPServer.h" 2 | #include "iotx_coap_internal.h" 3 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/iotx_coap_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __IOTX_COAP_CONFIG__ 2 | #define __IOTX_COAP_CONFIG__ 3 | 4 | #define COAP_MSG_MAX_TOKEN_LEN 8 5 | #define COAP_MSG_MAX_OPTION_NUM 12 6 | #define COAP_MSG_MAX_PATH_LEN 128 7 | #ifndef COAP_LARGE_MEMORY_SUPPORT 8 | #define COAP_MSG_MAX_PDU_LEN 1280 9 | #else 10 | #define COAP_MSG_MAX_PDU_LEN 4096 11 | #endif 12 | 13 | #ifndef CONFIG_COAP_AUTH_TIMEOUT 14 | #define CONFIG_COAP_AUTH_TIMEOUT (3 * 1000) 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/server/CoAPInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef __COAP_INTERNAL_H__ 8 | #define __COAP_INTERNAL_H__ 9 | #include "CoAPNetwork.h" 10 | #include "CoAPExport.h" 11 | #include "iotx_coap_internal.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif /* __cplusplus */ 16 | 17 | 18 | typedef struct 19 | { 20 | void *list_mutex; 21 | struct list_head list; 22 | unsigned char count; 23 | unsigned char maxcount; 24 | }CoAPList; 25 | 26 | 27 | typedef struct 28 | { 29 | unsigned short message_id; 30 | NetworkContext *p_network; 31 | CoAPEventNotifier notifier; 32 | unsigned char *sendbuf; 33 | unsigned char *recvbuf; 34 | CoAPList sendlist; 35 | CoAPList obsserver; 36 | CoAPList obsclient; 37 | CoAPList resource; 38 | unsigned int waittime; 39 | void *appdata; 40 | void *mutex; 41 | }CoAPIntContext; 42 | 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif /* __cplusplus */ 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/server/CoAPNetwork.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __CoAPNETWORK_H__ 6 | #define __CoAPNETWORK_H__ 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif /* __cplusplus */ 12 | 13 | 14 | typedef enum { 15 | COAP_NETWORK_NOSEC = 0, 16 | COAP_NETWORK_DTLS, 17 | } CoAPNetworkType; 18 | 19 | typedef struct { 20 | CoAPNetworkType type; 21 | unsigned short port; 22 | intptr_t fd; 23 | } NetworkConf; 24 | 25 | typedef void NetworkContext; 26 | 27 | 28 | typedef struct { 29 | CoAPNetworkType type; 30 | char *group; 31 | unsigned short port; 32 | #ifdef COAP_DTLS_SUPPORT 33 | /* TODO: */ 34 | #endif 35 | } NetworkInit; 36 | 37 | NetworkContext *CoAPNetwork_init(const NetworkInit *p_param); 38 | 39 | 40 | int CoAPNetwork_write(NetworkContext *p_context, 41 | NetworkAddr *p_remote, 42 | const unsigned char *p_data, 43 | unsigned int datalen, 44 | unsigned int timeout); 45 | 46 | int CoAPNetwork_read(NetworkContext *p_context, 47 | NetworkAddr *p_remote, 48 | unsigned char *p_data, 49 | unsigned int datalen, 50 | unsigned int timeout); 51 | 52 | void CoAPNetwork_deinit(NetworkContext *p_context); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif /* __cplusplus */ 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/server/CoAPObserve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef __COAP_OBSERVE_H__ 7 | #define __COAP_OBSERVE_H__ 8 | #include "CoAPExport.h" 9 | #include "CoAPMessage.h" 10 | #include "CoAPResource.h" 11 | #include "iotx_coap_internal.h" 12 | 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif /* __cplusplus */ 17 | 18 | 19 | typedef struct 20 | { 21 | NetworkAddr remote; 22 | unsigned char token[COAP_MSG_MAX_TOKEN_LEN]; 23 | unsigned char tokenlen; 24 | unsigned char ctype; 25 | CoAPResource *p_resource_of_interest; 26 | unsigned int observer_sequence_num; 27 | CoAPMessageCode msg_type; 28 | struct list_head obslist; 29 | } CoapObserver; 30 | 31 | typedef struct 32 | { 33 | NetworkAddr remote; 34 | unsigned char token[COAP_MSG_MAX_TOKEN_LEN]; 35 | unsigned char tokenlen; 36 | CoAPSendMsgHandler callback; 37 | unsigned int max_age; 38 | struct list_head obslist; 39 | void *userdata; 40 | } CoAPObservable; 41 | 42 | int CoAPObsServer_init(CoAPContext *context, unsigned char obs_maxcount); 43 | int CoAPObsServer_deinit(CoAPContext *context); 44 | 45 | int CoAPObsServer_add(CoAPContext *context, const char *path, NetworkAddr *remote, CoAPMessage *request); 46 | int CoapObsServer_delete(CoAPContext *context, NetworkAddr *remote, 47 | CoAPResource *resource); 48 | int CoapObsServerAll_delete(CoAPContext *context, NetworkAddr *remote); 49 | 50 | int CoAPObsServer_notify(CoAPContext *context, 51 | const char *path, unsigned char *payload, 52 | unsigned short payloadlen, CoAPDataEncrypt handler); 53 | 54 | int CoAPObsClient_init(CoAPContext *context, unsigned char obs_maxcount); 55 | int CoAPObsClient_deinit(CoAPContext *context); 56 | int CoAPObsClient_add(CoAPContext *context, CoAPMessage *message, NetworkAddr *remote, CoAPSendNode *sendnode); 57 | int CoAPObsClient_delete(CoAPContext *context, CoAPMessage *message); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif /* __cplusplus */ 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/server/CoAPResource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #ifndef __COAP_RESOURCE_H__ 9 | #define __COAP_RESOURCE_H__ 10 | 11 | #include 12 | #include "iotx_coap_internal.h" 13 | #include "CoAPExport.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif /* __cplusplus */ 18 | 19 | #define COAP_MAX_PATH_CHECKSUM_LEN (5) 20 | 21 | typedef struct { 22 | unsigned short permission; 23 | CoAPRecvMsgHandler callback; 24 | unsigned int ctype; 25 | unsigned int maxage; 26 | struct list_head reslist; 27 | char path[COAP_MAX_PATH_CHECKSUM_LEN]; 28 | char *filter_path; 29 | path_type_t path_type; 30 | } CoAPResource; 31 | 32 | int CoAPResource_init(CoAPContext *context, int res_maxcount); 33 | 34 | int CoAPPathMD5_sum(const char *path, int len, char outbuf[], int outlen); 35 | 36 | int CoAPResource_register(CoAPContext *context, const char *path, 37 | unsigned short permission, unsigned int ctype, 38 | unsigned int maxage, CoAPRecvMsgHandler callback); 39 | 40 | CoAPResource *CoAPResourceByPath_get(CoAPContext *context, const char *path); 41 | 42 | int CoAPResource_deinit(CoAPContext *context); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif /* __cplusplus */ 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /iotkit-embedded/coap_server/server/CoAPServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __COAP_SERVER_H__ 6 | #define __COAP_SERVER_H__ 7 | 8 | #include "CoAPExport.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif /* __cplusplus */ 13 | #define COAP_SERV_MULTITHREAD 14 | 15 | CoAPContext *CoAPServer_init(); 16 | 17 | void CoAPServer_add_timer (void (*on_timer)(void*)); 18 | void CoAPServer_loop(CoAPContext *context); 19 | 20 | void CoAPServer_deinit(CoAPContext *context); 21 | 22 | int CoAPServer_register(CoAPContext *context, const char *uri, CoAPRecvMsgHandler callback); 23 | 24 | int CoAPServerMultiCast_send(CoAPContext *context, NetworkAddr *remote, const char *uri, 25 | unsigned char *buff, unsigned short len, CoAPSendMsgHandler callback, unsigned short *msgid); 26 | 27 | int CoAPServerResp_send(CoAPContext *context, NetworkAddr *remote, unsigned char *buff, unsigned short len, void *req, 28 | const char *paths, CoAPSendMsgHandler callback, unsigned short *msgid, char qos); 29 | 30 | void CoAPServer_thread_leave(); 31 | #ifdef __cplusplus 32 | } 33 | #endif /* __cplusplus */ 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/dev_bind_api.h: -------------------------------------------------------------------------------- 1 | DLL_IOT_API int awss_report_cloud(void); 2 | 3 | /** 4 | ** @brief check reset flag in perisistent storage. 5 | ** 6 | ** @retval -1 : failure 7 | ** @retval 0 : sucess 8 | ** @note 9 | ** check reset flag in perisistent storage, if device failed to report reset message last time, retry it. 10 | **/ 11 | DLL_IOT_API int awss_check_reset(void); 12 | 13 | /** 14 | ** @brief report reset to cloud. 15 | ** 16 | ** @retval -1 : failure 17 | ** @retval 0 : sucess 18 | ** @note 19 | ** device will save reset flag if device dosen't connect cloud, device will fails to send reset to cloud. 20 | ** when connection between device and cloud is ready, device will retry to report reset to cloud. 21 | **/ 22 | DLL_IOT_API int awss_report_reset(void); 23 | 24 | /** 25 | ** @brief stop to report reset to cloud. 26 | ** 27 | ** @retval -1 : failure 28 | ** @retval 0 : sucess 29 | ** @note 30 | ** just stop report reset to cloud without any touch reset flag in flash. 31 | **/ 32 | DLL_IOT_API int awss_stop_report_reset(void); 33 | 34 | DLL_IOT_API int awss_bind_deinit(void); 35 | 36 | /** 37 | ** @brief deinit bind operation. 38 | ** 39 | ** @retval -1 : failure 40 | ** @retval 0 : sucess 41 | ** @note 42 | ** stop report token to cloud and release coap topic and handler. 43 | **/ 44 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/dev_bind_wrapper.h: -------------------------------------------------------------------------------- 1 | #include "infra_types.h" 2 | #include "infra_defs.h" 3 | #include "wrappers_defs.h" 4 | #ifdef WIFI_PROVISION_ENABLED 5 | #include "iot_import_awss.h" 6 | #endif 7 | int HAL_Snprintf(char *str, const int len, const char *fmt, ...); 8 | int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN]); 9 | int HAL_GetProductSecret(char *product_secret); 10 | int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN]); 11 | int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN]); 12 | void *HAL_Timer_Create(const char *name, void (*func)(void *), void *user_data); 13 | int HAL_Timer_Stop(void *timer); 14 | int HAL_Timer_Start(void *timer, int ms); 15 | int HAL_Timer_Delete(void *timer); 16 | char *HAL_Wifi_Get_Mac(char mac_str[HAL_MAC_LEN]); 17 | void HAL_Srandom(uint32_t seed); 18 | uint32_t HAL_Random(uint32_t region); 19 | void HAL_Reboot(); 20 | void *HAL_MutexCreate(void); 21 | void HAL_SleepMs(uint32_t ms); 22 | void HAL_MutexDestroy(void *mutex); 23 | void HAL_MutexLock(void *mutex); 24 | void HAL_MutexUnlock(void *mutex); 25 | void *HAL_Malloc(uint32_t size); 26 | void HAL_Free(void *ptr); 27 | int HAL_Sys_Net_Is_Ready(); 28 | uint64_t HAL_UptimeMs(void); 29 | uint32_t HAL_Wifi_Get_IP(char ip_str[NETWORK_ADDR_LEN], const char *ifname); 30 | #ifdef WIFI_PROVISION_ENABLED 31 | int HAL_Wifi_Get_Ap_Info(char ssid[HAL_MAX_SSID_LEN],char passwd[HAL_MAX_PASSWD_LEN],uint8_t bssid[ETH_ALEN]); 32 | int HAL_Awss_Connect_Ap( 33 | _IN_ uint32_t connection_timeout_ms, 34 | _IN_ char ssid[HAL_MAX_SSID_LEN], 35 | _IN_ char passwd[HAL_MAX_PASSWD_LEN], 36 | _IN_OPT_ enum AWSS_AUTH_TYPE auth, 37 | _IN_OPT_ enum AWSS_ENC_TYPE encry, 38 | _IN_OPT_ uint8_t bssid[ETH_ALEN], 39 | _IN_OPT_ uint8_t channel); 40 | #endif 41 | /* dev reset */ 42 | int HAL_Kv_Set(const char *key, const void *val, int len, int sync); 43 | int HAL_Kv_Get(const char *key, void *val, int *buffer_len); 44 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_bind.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | #include "dev_bind_internal.h" 5 | #ifdef WIFI_PROVISION_ENABLED 6 | #ifndef AWSS_DISABLE_REGISTRAR 7 | #include "awss_enrollee.h" 8 | #endif 9 | #endif 10 | 11 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 12 | extern "C" { 13 | #endif 14 | 15 | static void *awss_bind_mutex = NULL; 16 | int awss_report_cloud() 17 | { 18 | if (awss_bind_mutex == NULL) { 19 | awss_bind_mutex = HAL_MutexCreate(); 20 | if (awss_bind_mutex == NULL) { 21 | return -1; 22 | } 23 | } 24 | 25 | HAL_MutexLock(awss_bind_mutex); 26 | 27 | awss_cmp_online_init(); 28 | #ifdef DEVICE_MODEL_ENABLED 29 | awss_check_reset(); 30 | #endif 31 | awss_report_token(); 32 | 33 | awss_cmp_local_init(AWSS_LC_INIT_BIND); 34 | awss_dev_bind_notify_stop(); 35 | awss_dev_bind_notify(); 36 | #ifdef WIFI_PROVISION_ENABLED 37 | #ifndef AWSS_DISABLE_REGISTRAR 38 | awss_registrar_init(); 39 | #endif 40 | AWSS_DISP_STATIS(); 41 | AWSS_REPORT_STATIS("RDA5981"); 42 | #endif 43 | AWSS_DB_DISP_STATIS(); 44 | AWSS_DB_REPORT_STATIS("RDA5981"); 45 | HAL_MutexUnlock(awss_bind_mutex); 46 | return 0; 47 | } 48 | 49 | int awss_bind_deinit() 50 | { 51 | if (awss_bind_mutex) { 52 | HAL_MutexLock(awss_bind_mutex); 53 | } 54 | 55 | #ifdef DEVICE_MODEL_ENABLED 56 | awss_stop_report_reset(); 57 | #endif 58 | awss_stop_report_token(); 59 | awss_cmp_online_deinit(); 60 | 61 | awss_dev_bind_notify_stop(); 62 | 63 | awss_cmp_local_deinit(1); 64 | #ifdef WIFI_PROVISION_ENABLED 65 | #ifndef AWSS_DISABLE_REGISTRAR 66 | awss_registrar_deinit(); 67 | #endif 68 | AWSS_CLEAR_STATIS(); 69 | #endif 70 | AWSS_DB_CLEAR_STATIS(); 71 | 72 | if (awss_bind_mutex) { 73 | HAL_MutexUnlock(awss_bind_mutex); 74 | HAL_MutexDestroy(awss_bind_mutex); 75 | } 76 | 77 | awss_bind_mutex = NULL; 78 | 79 | return 0; 80 | } 81 | 82 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 83 | } 84 | #endif 85 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_bind_statis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_BIND_STATIS_H__ 6 | #define __AWSS_BIND_STATIS_H__ 7 | 8 | #ifndef AWSS_SUPPORT_DEV_BIND_STATIS 9 | #define AWSS_SUPPORT_DEV_BIND_STATIS 10 | #endif 11 | 12 | enum { 13 | AWSS_DB_STATIS_START, 14 | AWSS_DB_STATIS_SUC, 15 | }; 16 | 17 | #ifdef AWSS_SUPPORT_DEV_BIND_STATIS 18 | struct awss_statis_dev_bind_t { 19 | uint32_t dev_bind_cnt; /* the count of token sync */ 20 | uint32_t dev_bind_suc; /* the successful count of token sync */ 21 | uint32_t dev_bind_time_mean; /* the mean time of token sync */ 22 | uint32_t dev_bind_time_max; /* the max time of token sync */ 23 | uint32_t dev_bind_time_min; /* the min time of token sync */ 24 | uint32_t dev_bind_start; /* the start time to sync token */ 25 | uint32_t dev_bind_end; /* the end time of token sync */ 26 | }; /* statistics for token sync */ 27 | 28 | 29 | int awss_bind_report_statis(const char *module); 30 | void awss_bind_update_statis(int type); 31 | void awss_bind_clear_statis(); 32 | void awss_bind_disp_statis(); 33 | 34 | 35 | #define AWSS_DB_UPDATE_STATIS(type) awss_bind_update_statis(type) 36 | #define AWSS_DB_DISP_STATIS() awss_bind_disp_statis() 37 | #define AWSS_DB_CLEAR_STATIS() awss_bind_clear_statis() 38 | #define AWSS_DB_REPORT_STATIS(m) awss_bind_report_statis(m) 39 | #else 40 | #define AWSS_DB_UPDATE_STATIS(type) 41 | #define AWSS_DB_DISP_STATIS() 42 | #define AWSS_DB_CLEAR_STATIS() 43 | #define AWSS_DB_REPORT_STATIS(m) 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | #include "dev_bind_internal.h" 5 | 6 | extern int iotx_event_post(int event); 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" { 10 | #endif 11 | 12 | int awss_event_post(int event) 13 | { 14 | int ret = 0; 15 | void *cb = NULL; 16 | 17 | ret = iotx_event_post(event); 18 | 19 | cb = (void *)iotx_event_callback(ITE_AWSS_STATUS); 20 | if (cb) { 21 | ret = ((int (*)(int))cb)(event); 22 | } 23 | 24 | return ret; 25 | } 26 | 27 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_EVENT_H__ 6 | #define __AWSS_EVENT_H__ 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" 10 | { 11 | #endif 12 | 13 | int awss_event_post(int event); 14 | 15 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_INFO_H__ 6 | #define __AWSS_INFO_H__ 7 | 8 | #include 9 | 10 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 11 | extern "C" { 12 | #endif 13 | 14 | int process_get_device_info(void *ctx, void *resource, void *remote, void *request, char is_mcast, int type); 15 | int awss_process_mcast_get_connectap_info(void *ctx, void *resource, void *remote, void *request); 16 | int awss_process_ucast_get_connectap_info(void *ctx, void *resource, void *remote, void *request); 17 | 18 | int awss_stop_connectap_monitor(); 19 | int awss_start_connectap_monitor(); 20 | 21 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 22 | } 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_LOG_H__ 6 | #define __AWSS_LOG_H__ 7 | 8 | #include "infra_log.h" 9 | 10 | #define awss_flow(...) log_flow("awss", __VA_ARGS__) 11 | #define awss_debug(...) log_debug("awss", __VA_ARGS__) 12 | #define awss_info(...) log_info("awss", __VA_ARGS__) 13 | #define awss_warn(...) log_warning("awss", __VA_ARGS__) 14 | #define awss_err(...) log_err("awss", __VA_ARGS__) 15 | #define awss_crit(...) log_crit("awss", __VA_ARGS__) 16 | #define awss_emerg(...) log_emerg("awss", __VA_ARGS__) 17 | #define awss_trace(...) log_crit("awss", __VA_ARGS__) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_notify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_NOTIFY_H__ 6 | #define __AWSS_NOTIFY_H__ 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" 10 | { 11 | #endif 12 | 13 | enum { 14 | AWSS_NOTIFY_DEV_INFO = 0, 15 | AWSS_NOTIFY_DEV_BIND_TOKEN, 16 | AWSS_NOTIFY_DEV_RAND_SIGN, 17 | AWSS_NOTIFY_SUCCESS, 18 | AWSS_NOTIFY_TYPE_MAX, 19 | }; 20 | 21 | #ifdef WIFI_PROVISION_ENABLED 22 | int awss_suc_notify(); 23 | int awss_devinfo_notify(); 24 | int awss_suc_notify_stop(); 25 | int awss_devinfo_notify_stop(); 26 | #endif 27 | 28 | int awss_dev_bind_notify(); 29 | int awss_dev_bind_notify_stop(); 30 | int awss_notify_dev_info(int type, int count); 31 | int online_mcast_get_device_info(void *ctx, void *resource, void *remote, void *request); 32 | int online_ucast_get_device_info(void *ctx, void *resource, void *remote, void *request); 33 | 34 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_reset.h: -------------------------------------------------------------------------------- 1 | #ifndef __AWSS_RESET__ 2 | #define __AWSS_RESET__ 3 | 4 | #define AWSS_RESET_PKT_LEN (256) 5 | #define AWSS_RESET_TOPIC_LEN (128) 6 | #define AWSS_RESET_MSG_ID_LEN (16) 7 | 8 | #define TOPIC_RESET_REPORT "/sys/%s/%s/thing/reset" 9 | #define TOPIC_RESET_REPORT_REPLY "/sys/%s/%s/thing/reset_reply" 10 | #define METHOD_RESET_REPORT "thing.reset" 11 | 12 | #define AWSS_RESET_REQ_FMT "{\"id\":%s, \"version\":\"1.0\", \"method\":\"%s\", \"params\":%s}" 13 | 14 | #define AWSS_KV_RST "awss.rst" 15 | 16 | int awss_check_reset(); 17 | 18 | /** 19 | * @brief report reset to cloud. 20 | * 21 | * @retval -1 : failure 22 | * @retval 0 : sucess 23 | * @note 24 | * device will save reset flag if device dosen't connect cloud, device will fails to send reset to cloud. 25 | * when connection between device and cloud is ready, device will retry to report reset to cloud. 26 | */ 27 | int awss_report_reset(); 28 | 29 | /** 30 | * @brief stop to report reset to cloud. 31 | * 32 | * @retval -1 : failure 33 | * @retval 0 : sucess 34 | * @note 35 | * just stop report reset to cloud without any touch reset flag in flash. 36 | */ 37 | int awss_stop_report_reset(); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_reset/awss_dev_reset_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _AWSS_DEV_RESET_INTERNAL_H_ 2 | #define _AWSS_DEV_RESET_INTERNAL_H_ 3 | 4 | #include "os.h" 5 | 6 | #ifdef INFRA_LOG 7 | #include "infra_log.h" 8 | #define devrst_err(...) log_err("devrst", __VA_ARGS__) 9 | #define devrst_info(...) log_info("devrst", __VA_ARGS__) 10 | #define devrst_debug(...) log_debug("devrst", __VA_ARGS__) 11 | #else 12 | #define devrst_info(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 13 | #define devrst_err(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 14 | #define devrst_debug(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 15 | #endif 16 | 17 | #ifdef INFRA_MEM_STATS 18 | #include "infra_mem_stats.h" 19 | #define devrst_malloc(size) LITE_malloc(size, MEM_MAGIC, "devrst") 20 | #define devrst_free(ptr) LITE_free(ptr) 21 | #else 22 | #define devrst_malloc(size) HAL_Malloc(size) 23 | #define devrst_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 24 | #endif 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | #include "dev_bind_internal.h" 5 | 6 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 7 | extern "C" 8 | { 9 | #endif 10 | 11 | int awss_stop_timer(void *timer) 12 | { 13 | if (timer == NULL) 14 | return 0; 15 | HAL_Timer_Stop(timer); 16 | HAL_Timer_Delete(timer); 17 | return 0; 18 | } 19 | #if 0 20 | int awss_start_timer(void **timer, const char *name, void *func, void *user_data, int ms) 21 | { 22 | if (timer == NULL) 23 | return -1; 24 | *timer = HAL_Timer_Create(name, (void (*)(void *))func, user_data); 25 | if (*timer == NULL) 26 | return -1; 27 | HAL_Timer_Stop(*timer); 28 | HAL_Timer_Start(*timer, ms); 29 | return 0; 30 | } 31 | #endif 32 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_TIMER_H__ 6 | #define __AWSS_TIMER_H__ 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" 10 | { 11 | #endif 12 | 13 | int awss_stop_timer(void *timer); 14 | 15 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/awss_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_UTILS_H__ 6 | #define __AWSS_UTILS_H__ 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" { 10 | #endif 11 | 12 | #include "os.h" 13 | #if 0 14 | #include "iotx_utils.h" 15 | #endif 16 | #include "infra_string.h" 17 | 18 | /** 19 | * @brief string to hex 20 | * 21 | * @param[in] str: input hex string 22 | * @param[in] str_len: length of input hex string 23 | * @param[out] out: output hex byte stream 24 | * @param[in/out] output_len: [in] for output buffer size, [out] for 25 | * output hex byte len 26 | * @Note None. 27 | * 28 | * @retval return num of hex bytes converted, 0 means error. 29 | */ 30 | #define utils_str_to_hex LITE_hexstr_convert 31 | 32 | 33 | /** 34 | * @brief hex to string 35 | * 36 | * @param[in] buf: input hex byte stream 37 | * @param[in] buf_len: input stream length in byte 38 | * @param[out] str: encoded hex string 39 | * @param[in/out] str_len: [in] for str buffer size, [out] for 40 | * encoded string length 41 | * @Note output str buffer is NULL-terminated(if str_buf_len is longer enough) 42 | * 43 | * @retval return length of str converted, 0 means error. 44 | */ 45 | #define utils_hex_to_str(buf, buf_len, str, str_buf_len) LITE_hexbuf_convert(buf, str, buf_len, 1) 46 | 47 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/dev_bind_internal.h: -------------------------------------------------------------------------------- 1 | #include "infra_config.h" 2 | #include 3 | #include 4 | #include 5 | #include "awss_event.h" 6 | #include "awss_timer.h" 7 | #include "awss_log.h" 8 | #include "passwd.h" 9 | #include "awss_utils.h" 10 | #include "awss_reset.h" 11 | #include "infra_compat.h" 12 | #include "awss_packet.h" 13 | #include "awss_notify.h" 14 | #include "awss_cmp.h" 15 | #include "awss_cmp.h" 16 | #include "sha256.h" 17 | #include "infra_json_parser.h" 18 | #include "mqtt_api.h" 19 | #include "awss_dev_reset_internal.h" 20 | #include "awss_info.h" 21 | #include "awss_bind_statis.h" 22 | #include "dev_bind_wrapper.h" 23 | #include "coap_api.h" 24 | #include "iotx_coap.h" 25 | #ifdef WIFI_PROVISION_ENABLED 26 | #include "awss_statis.h" 27 | #endif 28 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/os/os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_OS_H__ 6 | #define __AWSS_OS_H__ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | #include 12 | #include "infra_defs.h" 13 | #include 14 | #include 15 | #include "infra_compat.h" 16 | 17 | #ifndef _IN_OPT_ 18 | #define _IN_OPT_ 19 | #endif 20 | #ifndef _OUT_ 21 | #define _OUT_ 22 | #endif 23 | #ifndef _OUT_OPT_ 24 | #define _OUT_OPT_ 25 | #endif 26 | #ifndef _INOUT_ 27 | #define _INOUT_ 28 | #endif 29 | #ifndef _INOUT_OPT_ 30 | #define _INOUT_OPT_ 31 | #endif 32 | 33 | /** @defgroup group_os os 34 | * @{ 35 | */ 36 | #define OS_MAC_LEN HAL_MAC_LEN 37 | #define OS_ETH_ALEN ETH_ALEN 38 | #define OS_IP_LEN (NETWORK_ADDR_LEN) 39 | #define OS_MAX_PASSWD_LEN HAL_MAX_PASSWD_LEN 40 | #define OS_MAX_SSID_LEN HAL_MAX_SSID_LEN 41 | #define OS_PRODUCT_KEY_LEN IOTX_PRODUCT_KEY_LEN 42 | #define OS_PRODUCT_SECRET_LEN IOTX_PRODUCT_SECRET_LEN 43 | #define OS_DEVICE_NAME_LEN IOTX_DEVICE_NAME_LEN 44 | #define OS_DEVICE_SECRET_LEN IOTX_DEVICE_SECRET_LEN 45 | #define PLATFORM_AES_DECRYPTION HAL_AES_DECRYPTION 46 | #define PLATFORM_AES_ENCRYPTION HAL_AES_ENCRYPTION 47 | #define PLATFORM_MAX_SSID_LEN HAL_MAX_SSID_LEN 48 | #define PLATFORM_MAX_PASSWD_LEN HAL_MAX_PASSWD_LEN 49 | typedef void *p_HAL_Aes128_t; 50 | #define p_aes128_t p_HAL_Aes128_t 51 | 52 | char *os_wifi_get_mac_str(char mac_str[HAL_MAC_LEN]); 53 | char *os_wifi_str2mac(char mac_str[HAL_MAC_LEN], char mac[ETH_ALEN]); 54 | uint8_t *os_wifi_get_mac(uint8_t mac[ETH_ALEN]); 55 | uint32_t os_get_time_ms(void); 56 | 57 | int os_is_big_endian(void); 58 | uint16_t os_htobe16(uint16_t data); 59 | uint16_t os_htole16(uint16_t data); 60 | uint16_t os_be16toh(uint16_t data); 61 | uint16_t os_le16toh(uint16_t data); 62 | uint32_t os_le32toh(uint32_t data); 63 | uint16_t os_get_unaligned_be16(uint8_t *ptr); 64 | uint16_t os_get_unaligned_le16(uint8_t *ptr); 65 | uint32_t os_get_unaligned_be32(uint8_t *ptr); 66 | uint32_t os_get_unaligned_le32(uint8_t *ptr); 67 | void *os_zalloc(uint32_t size); 68 | uint32_t time_elapsed_ms_since(uint32_t start_timestamp); 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* SRC_OSA_ABSTRAC_H_ */ 74 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/passwd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_PASSWD_H__ 6 | #define __AWSS_PASSWD_H__ 7 | 8 | #define KEY_MAX_LEN (40) 9 | #define AES128_KEY_LEN (16) 10 | #define RANDOM_MAX_LEN (16) 11 | 12 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 13 | extern "C" 14 | { 15 | #endif 16 | 17 | enum { 18 | SSID_DECODE_TABLE = 0x0, 19 | NOTIFY_ENCODE_TABLE, 20 | DICT_CRYPT_TABLE_IDX_MAX, 21 | }; 22 | 23 | int awss_dict_crypt(char tab_idx, uint8_t *data, uint8_t len); 24 | #ifdef WIFI_PROVISION_ENABLED 25 | int produce_signature(uint8_t *sign, uint8_t *txt, uint32_t txt_len, const char *key); 26 | #endif 27 | 28 | extern uint8_t aes_random[RANDOM_MAX_LEN]; 29 | 30 | int awss_set_token(uint8_t token[RANDOM_MAX_LEN]); 31 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_bind/impl/sha256.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_SHA256_H__ 6 | #define __AWSS_SHA256_H__ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef struct SHA256_CTX { 13 | /* const HASH_VTAB * f; */ 14 | uint64_t count; 15 | uint8_t buf[64]; 16 | uint32_t state[8]; /* upto SHA2 */ 17 | } SHA256_CTX; 18 | 19 | /* typedef HASH_CTX SHA256_CTX; */ 20 | void SHA256_init(SHA256_CTX* ctx); 21 | void SHA256_update(SHA256_CTX* ctx, const void* data, int len); 22 | const uint8_t* SHA256_final(SHA256_CTX* ctx); 23 | /* Convenience method. Returns digest address. */ 24 | const uint8_t* SHA256_hash(const void* data, int len, uint8_t* digest); 25 | 26 | #ifndef SHA256_DIGEST_SIZE 27 | #define SHA256_DIGEST_SIZE 32 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif /*__cplusplus */ 33 | 34 | #endif /* SYSTEM_CORE_INCLUDE_MINCRYPT_SHA256_H_ */ 35 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/alcs_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef __ALCS_ADAPTER_H__ 8 | #define __ALCS_ADAPTER_H__ 9 | #if defined(__cplusplus) 10 | extern "C" { 11 | #endif 12 | 13 | #include "alcs_internal.h" 14 | #include "mqtt_api.h" 15 | #include "CoAPExport.h" 16 | #include "alcs_mqtt.h" 17 | #include "iotx_alcs.h" 18 | 19 | typedef struct iotx_alcs_send_msg_st { 20 | uint8_t token_len; 21 | uint8_t *token; 22 | char *uri; 23 | struct list_head linked_list; 24 | } iotx_alcs_send_msg_t, *iotx_alcs_send_msg_pt; 25 | 26 | typedef enum { 27 | IOTX_ALCS_SUBDEV_DISCONNCET_CLOUD, 28 | IOTX_ALCS_SUBDEV_CONNECT_CLOUD 29 | } iotx_alcs_subdev_stage_t; 30 | 31 | #define IOTX_ALCS_SUBDEV_RETRY_INTERVAL_MS (10000) 32 | 33 | typedef struct iotx_alcs_subdev_item_st { 34 | char product_key[IOTX_PRODUCT_KEY_LEN + 1]; 35 | char device_name[IOTX_DEVICE_NAME_LEN + 1]; 36 | char prefix[ALCS_MQTT_PREFIX_MAX_LEN]; 37 | char secret[ALCS_MQTT_SECRET_MAX_LEN]; 38 | uint8_t stage; 39 | uint64_t retry_ms; 40 | struct list_head linked_list; 41 | } iotx_alcs_subdev_item_t, *iotx_alcs_subdev_item_pt; 42 | 43 | typedef void (*iotx_alcs_auth_timer_fnuc_t)(CoAPContext *); 44 | 45 | typedef struct iotx_alcs_adapter_st { 46 | void *mutex; 47 | int local_cloud_inited; 48 | CoAPContext *coap_ctx; 49 | uint8_t role; 50 | iotx_alcs_auth_timer_fnuc_t alcs_client_auth_timer_func; 51 | iotx_alcs_auth_timer_fnuc_t alcs_server_auth_timer_func; 52 | iotx_alcs_event_handle_t *alcs_event_handle; 53 | struct list_head alcs_send_list; 54 | struct list_head alcs_subdev_list; 55 | char local_ip[NETWORK_ADDR_LEN]; 56 | uint16_t local_port; 57 | } iotx_alcs_adapter_t, *iotx_alcs_adapter_pt; 58 | 59 | int iotx_alcs_subdev_insert(iotx_alcs_subdev_item_t *item); 60 | int iotx_alcs_subdev_remove(const char *pk, const char *dn); 61 | int iotx_alcs_subdev_search(const char *pk, const char *dn, iotx_alcs_subdev_item_t **item); 62 | int iotx_alcs_subdev_update_stage(iotx_alcs_subdev_item_t *item); 63 | void iotx_alcs_send_list_handle(void *list_node, va_list *params); 64 | int iotx_alcs_adapter_list_init(iotx_alcs_adapter_t *adapter); 65 | 66 | #if defined(__cplusplus) 67 | } 68 | #endif 69 | #endif 70 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/alcs_base64.h: -------------------------------------------------------------------------------- 1 | #ifndef _ALCS_BASE64_H_ 2 | #define _ALCS_BASE64_H_ 3 | 4 | #include "infra_types.h" 5 | 6 | int utils_base64encode(const uint8_t *data, uint32_t inputLength, uint32_t outputLenMax, 7 | uint8_t *encodedData, uint32_t *outputLength); 8 | int utils_base64decode(const uint8_t *data, uint32_t inputLength, uint32_t outputLenMax, 9 | uint8_t *decodedData, uint32_t *outputLength); 10 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/alcs_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ALCS_INTERNAL_H_ 2 | #define _ALCS_INTERNAL_H_ 3 | 4 | #include "infra_config.h" 5 | #include "infra_types.h" 6 | #include "infra_defs.h" 7 | #include "infra_md5.h" 8 | #include "infra_sha1.h" 9 | #include "infra_json_parser.h" 10 | #include "alcs_base64.h" 11 | #include "dm_wrapper.h" 12 | 13 | #ifdef INFRA_MEM_STATS 14 | #include "infra_mem_stats.h" 15 | #define ALCS_malloc(size) LITE_malloc(size, MEM_MAGIC, "alcs") 16 | #define ALCS_ADAPTER_malloc(size) LITE_malloc(size, MEM_MAGIC, "alcs_adapter") 17 | #define ALCS_free(ptr) LITE_free(ptr) 18 | #else 19 | #define ALCS_malloc(size) HAL_Malloc(size) 20 | #define ALCS_ADAPTER_malloc(size) HAL_Malloc(size) 21 | #define ALCS_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 22 | #endif 23 | 24 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/alcs_localsetup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _ALCS_LOCALSETUP_H_ 8 | #define _ALCS_LOCALSETUP_H_ 9 | 10 | void alcs_localsetup_init(void *adapter_handle, void* coap_handler, char *product_key,char *device_name); 11 | void alcs_localsetup_add_sub_device (void *adapter_handle,char *product_key,char *device_name); 12 | void alcs_localsetup_deinit(void *handle); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_client_adapter.h: -------------------------------------------------------------------------------- 1 | #ifndef _DM_CLIENT_ADAPTER_H_ 2 | #define _DM_CLIENT_ADAPTER_H_ 3 | 4 | typedef struct { 5 | int fd; 6 | iotx_conn_info_t *conn_info; 7 | void *callback; 8 | } dm_client_ctx_t; 9 | 10 | int dm_client_open(void); 11 | int dm_client_connect(int timeout_ms); 12 | int dm_client_close(void); 13 | int dm_client_subscribe(char *uri, iotx_cm_data_handle_cb callback, void *context); 14 | int dm_client_unsubscribe(char *uri); 15 | int dm_client_publish(char *uri, unsigned char *payload, int payload_len, iotx_cm_data_handle_cb callback); 16 | int dm_client_yield(unsigned int timeout); 17 | 18 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_cota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_COTA_H_ 8 | #define _DM_COTA_H_ 9 | 10 | typedef struct { 11 | int is_report_new_config; 12 | } dm_cota_ctx_t; 13 | 14 | int dm_cota_init(void); 15 | int dm_cota_deinit(void); 16 | int dm_cota_perform_sync(_OU_ char *output, _IN_ int output_len); 17 | int dm_cota_get_config(const char *config_scope, const char *get_type, const char *attribute_keys); 18 | int dm_cota_status_check(void); 19 | 20 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_fota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_FOTA_H_ 8 | #define _DM_FOTA_H_ 9 | 10 | typedef struct { 11 | int is_report_new_config; 12 | } dm_fota_ctx_t; 13 | 14 | int dm_fota_init(void); 15 | int dm_fota_deinit(void); 16 | int dm_fota_perform_sync(_OU_ char *output, _IN_ int output_len); 17 | int dm_fota_status_check(void); 18 | int dm_fota_request_image(_IN_ const char *version, _IN_ int buffer_len); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_intf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _IOT_DM_API_H_ 8 | #define _IOT_DM_API_H_ 9 | 10 | typedef struct { 11 | void *mutex; 12 | void *cloud_connectivity; 13 | void *local_connectivity; 14 | iotx_dm_event_callback event_callback; 15 | } dm_api_ctx_t; 16 | 17 | #if defined(DEPRECATED_LINKKIT) 18 | typedef struct { 19 | void *mutex; 20 | int devid; 21 | lite_cjson_item_t *lite; 22 | } dm_api_property_t; 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_IPC_H_ 8 | #define _DM_IPC_H_ 9 | 10 | #include "iotx_dm_internal.h" 11 | 12 | typedef struct { 13 | iotx_dm_event_types_t type; 14 | char *data; 15 | } dm_ipc_msg_t; 16 | 17 | typedef struct { 18 | void *data; 19 | struct list_head linked_list; 20 | } dm_ipc_msg_node_t; 21 | 22 | typedef struct { 23 | int max_size; 24 | int size; 25 | struct list_head message_list; 26 | } dm_ipc_msg_list_t; 27 | 28 | typedef struct { 29 | void *mutex; 30 | dm_ipc_msg_list_t msg_list; 31 | } dm_ipc_t; 32 | 33 | int dm_ipc_init(int max_size); 34 | void dm_ipc_deinit(void); 35 | int dm_ipc_msg_insert(void *data); 36 | int dm_ipc_msg_next(void **data); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_message_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #if !defined(DM_MESSAGE_CACHE_DISABLED) 7 | #ifndef _DM_MESSAGE_CACHE_H_ 8 | #define _DM_MESSAGE_CACHE_H_ 9 | 10 | #include "iotx_dm_internal.h" 11 | 12 | #define DM_MSG_CACHE_TIMEOUT_MS_DEFAULT (10000) 13 | 14 | typedef struct { 15 | int msgid; 16 | int devid; 17 | iotx_dm_event_types_t response_type; 18 | char *data; 19 | uint64_t ctime; 20 | struct list_head linked_list; 21 | } dm_msg_cache_node_t; 22 | 23 | typedef struct { 24 | void *mutex; 25 | int dmc_list_size; 26 | struct list_head dmc_list; 27 | } dm_msg_cache_ctx_t; 28 | 29 | int dm_msg_cache_init(void); 30 | int dm_msg_cache_deinit(void); 31 | int dm_msg_cache_insert(int msg_id, int devid, iotx_dm_event_types_t type, char *data); 32 | int dm_msg_cache_search(_IN_ int msg_id, _OU_ dm_msg_cache_node_t **node); 33 | int dm_msg_cache_remove(int msg_id); 34 | void dm_msg_cache_tick(void); 35 | 36 | #endif 37 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_opt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #if !defined(DEVICE_MODEL_RAWDATA_SOLO) 6 | #ifndef _DM_OPT_H 7 | #define _DM_OPT_H 8 | 9 | typedef enum { 10 | DM_OPT_DOWNSTREAM_PROPERTY_POST_REPLY, 11 | DM_OPT_DOWNSTREAM_EVENT_POST_REPLY, 12 | DM_OPT_UPSTREAM_PROPERTY_SET_REPLY, 13 | DM_OPT_DOWNSTREAM_EVENT_PROPERTY_DESIRED_DELETE_REPLY, 14 | DM_OPT_DOWNSTREAM_EVENT_PROPERTY_DESIRED_GET_REPLY 15 | } dm_opt_t; 16 | 17 | typedef struct { 18 | int prop_post_reply_opt; 19 | int event_post_reply_opt; 20 | int prop_set_reply_opt; 21 | int prop_desired_get_reply_opt; 22 | int prop_desired_delete_reply_opt; 23 | } dm_opt_ctx; 24 | 25 | int dm_opt_set(dm_opt_t opt, void *data); 26 | int dm_opt_get(dm_opt_t opt, void *data); 27 | 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_ota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_OTA_H_ 8 | #define _DM_OTA_H_ 9 | 10 | typedef struct { 11 | void *ota_handle; 12 | char product_key[IOTX_PRODUCT_KEY_LEN + 1]; 13 | char device_name[IOTX_DEVICE_NAME_LEN + 1]; 14 | } dm_ota_ctx_t; 15 | 16 | int dm_ota_init(void); 17 | int dm_ota_sub(void); 18 | int dm_ota_deinit(void); 19 | int dm_ota_get_ota_handle(void **handle); 20 | #ifdef DEVICE_MODEL_GATEWAY 21 | #ifdef DEVICE_MODEL_SUBDEV_OTA 22 | int dm_ota_switch_device(int devid); 23 | #endif 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_server.h: -------------------------------------------------------------------------------- 1 | #ifndef _DM_SERVER_H_ 2 | #define _DM_SERVER_H_ 3 | 4 | #ifdef ALCS_ENABLED 5 | typedef struct { 6 | const char *uri_name; 7 | const char *uri_prefix; 8 | int auth_type; 9 | CoAPRecvMsgHandler callback; 10 | } dm_server_uri_map_t; 11 | 12 | #define DM_SERVER_ALCS_NO_AUTH (0) 13 | #define DM_SERVER_ALCS_AUTH (1) 14 | 15 | void dm_server_alcs_event_handler(void *pcontext, void *phandle, iotx_alcs_event_msg_t *msg); 16 | 17 | int dm_server_subscribe_all(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char device_name[IOTX_DEVICE_NAME_LEN + 1]); 18 | void dm_server_thing_service_property_set(CoAPContext *context, const char *paths, NetworkAddr *remote, 19 | CoAPMessage *message); 20 | void dm_server_thing_service_property_get(CoAPContext *context, const char *paths, NetworkAddr *remote, 21 | CoAPMessage *message); 22 | void dm_server_thing_service_property_post(CoAPContext *context, const char *paths, NetworkAddr *remote, 23 | CoAPMessage *message); 24 | void dm_server_thing_dev_core_service_dev(CoAPContext *context, const char *paths, NetworkAddr *remote, 25 | CoAPMessage *message); 26 | void dm_server_thing_service_request(CoAPContext *context, const char *paths, NetworkAddr *remote, 27 | CoAPMessage *message); 28 | #endif 29 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_server_adapter.h: -------------------------------------------------------------------------------- 1 | #ifndef _DM_SERVER_ADAPTER_H_ 2 | #define _DM_SERVER_ADAPTER_H_ 3 | 4 | #ifdef ALCS_ENABLED 5 | 6 | #define DM_SERVER_ALCS_ADDR "224.0.1.187" 7 | #define DM_SERVER_ALCS_PORT (5863) 8 | #define DM_SERVER_ALCS_SEND_MAXCOUNT (16) 9 | #define DM_SERVER_ALCS_WAITTIME (200) 10 | #define DM_SERVER_ALCS_OBS_MAXCOUNT (16) 11 | #define DM_SERVER_ALCS_RES_MAXCOUNT (255) 12 | 13 | typedef struct { 14 | void *conn_handle; 15 | } dm_server_ctx_t; 16 | 17 | typedef struct { 18 | char *ip; 19 | uint16_t port; 20 | char *token; 21 | int token_len; 22 | } dm_server_alcs_context_t; 23 | 24 | int dm_server_open(void); 25 | int dm_server_connect(void); 26 | int dm_server_close(void); 27 | int dm_server_send(char *uri, unsigned char *payload, int payload_len, void *context); 28 | int dm_server_subscribe(char *uri, CoAPRecvMsgHandler callback, int auth_type); 29 | int dm_server_add_device(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char device_name[IOTX_DEVICE_NAME_LEN + 1]); 30 | int dm_server_del_device(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char device_name[IOTX_DEVICE_NAME_LEN + 1]); 31 | int dm_server_yield(void); 32 | 33 | #endif 34 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_tsl_alink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #if defined(DEPRECATED_LINKKIT) 6 | #ifndef _DM_TSL_ALINK_H_ 7 | #define _DM_TSL_ALINK_H_ 8 | 9 | /** 10 | * @brief Create TSL struct from TSL string. 11 | * This function used to parse TSL string into TSL struct. 12 | * 13 | * @param tsl. The TSL string in JSON format. 14 | * @param tsl_len. The length of tsl 15 | * @param shadow. The pointer of TSL Struct pointer, will be malloc memory. 16 | * This memory should be free by dm_shw_destroy. 17 | * 18 | * @return success or fail. 19 | * 20 | */ 21 | int dm_tsl_alink_create(_IN_ const char *tsl, _IN_ int tsl_len, _OU_ dm_shw_t **shadow); 22 | 23 | #endif 24 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/dm_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_UTILS_H_ 8 | #define _DM_UTILS_H_ 9 | 10 | #define DM_UTILS_UINT16_STRLEN (5) 11 | #define DM_UTILS_UINT32_STRLEN (10) 12 | #define DM_UTILS_UINT64_STRLEN (20) 13 | 14 | int dm_utils_copy_direct(void *input, int input_len, void **output, int output_len); 15 | 16 | int dm_utils_copy(void *input, int input_len, void **output, int output_len); 17 | 18 | /** 19 | * @brief search array index in a string. 20 | * This function used to search array index in a string. 21 | * 22 | * @param input. The string to be searched 23 | * @param input_len. The length of input 24 | * @param partial_input_len. The length of input except [xx] 25 | * @param array_input_len. The length of input include [xx] 26 | * @param array_index. The array index in [xx] 27 | * 28 | * @warning input must be type of "xxxxx[xx]" 29 | * @return success or fail. 30 | * 31 | */ 32 | int dm_utils_strarr_index(char *input, int input_len, 33 | int *partial_input_len, int *array_input_len, int *array_index); 34 | 35 | int dm_utils_itoa_direct(int input, char **output); 36 | int dm_utils_itoa(int input, char **output); 37 | int dm_utils_ftoa_direct(double input, char **output); 38 | int dm_utils_ftoa(double input, char **output); 39 | int dm_utils_hex_to_str(unsigned char *input, int input_len, char **output); 40 | int dm_utils_str_to_hex(char *input, int input_len, unsigned char **output, int *output_len); 41 | int dm_utils_memtok(char *input, int input_len, char delimiter, int index, int *offset); 42 | int dm_utils_replace_char(char *input, int input_len, char src, char dest); 43 | int dm_utils_service_name(const char *prefix, const char *name, char product_key[IOTX_PRODUCT_KEY_LEN + 1], 44 | char device_name[IOTX_DEVICE_NAME_LEN + 1], char **service_name); 45 | int dm_utils_uri_add_prefix(const char *prefix, char *uri, char **new_uri); 46 | int dm_utils_json_parse(const char *payload, int payload_len, int type, lite_cjson_t *lite); 47 | int dm_utils_json_object_item(lite_cjson_t *lite, const char *key, int key_len, int type, 48 | lite_cjson_t *lite_item); 49 | void *dm_utils_malloc(unsigned int size); 50 | void dm_utils_free(void *ptr); 51 | #endif 52 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/impl_gateway.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _LINKKIT_GATEWAY_LEGACY_H_ 6 | #define _LINKKIT_GATEWAY_LEGACY_H_ 7 | 8 | #include "infra_list.h" 9 | #include "linkkit_gateway_export.h" 10 | 11 | #define LINKKIT_GATEWAY_LEGACY_KEY_ID "id" 12 | #define LINKKIT_GATEWAY_LEGACY_KEY_CODE "code" 13 | #define LINKKIT_GATEWAY_LEGACY_KEY_DEVID "devid" 14 | #define LINKKIT_GATEWAY_LEGACY_KEY_SERVICEID "serviceid" 15 | #define LINKKIT_GATEWAY_LEGACY_KEY_PROPERTYID "propertyid" 16 | #define LINKKIT_GATEWAY_LEGACY_KEY_EVENTID "eventid" 17 | #define LINKKIT_GATEWAY_LEGACY_KEY_PAYLOAD "payload" 18 | #define LINKKIT_GATEWAY_LEGACY_KEY_PRODUCT_KEY "productKey" 19 | #define LINKKIT_GATEWAY_LEGACY_KEY_TIME "time" 20 | #define LINKKIT_GATEWAY_LEGACY_KEY_VERSION "version" 21 | 22 | #define LINKKIT_GATEWAY_LEGACY_SYNC_DEFAULT_TIMEOUT_MS (10000) 23 | 24 | typedef struct { 25 | int devid; 26 | linkkit_cbs_t *callback; 27 | void *callback_ctx; 28 | struct list_head linked_list; 29 | } linkkit_gateway_dev_callback_node_t; 30 | 31 | typedef void (*linkkit_gateway_upstream_async_callback)(int retval, void *ctx); 32 | typedef struct { 33 | int msgid; 34 | void *semaphore; 35 | int code; 36 | struct list_head linked_list; 37 | } linkkit_gateway_upstream_sync_callback_node_t; 38 | 39 | typedef struct { 40 | int msgid; 41 | int timeout_ms; 42 | uint64_t timestamp_ms; 43 | linkkit_gateway_upstream_async_callback callback; 44 | void *callback_ctx; 45 | struct list_head linked_list; 46 | } linkkit_gateway_upstream_async_callback_node_t; 47 | 48 | typedef struct { 49 | void *mutex; 50 | void *upstream_mutex; 51 | int is_inited; 52 | int is_started; 53 | linkkit_params_t init_params; 54 | void *dispatch_thread; 55 | handle_service_fota_callback_fp_t fota_callback; 56 | struct list_head dev_callback_list; 57 | struct list_head upstream_sync_callback_list; 58 | struct list_head upstream_async_callback_list; 59 | } linkkit_gateway_legacy_ctx_t; 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/impl_ntp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NTP_H 7 | #define NTP_H 8 | 9 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 10 | extern "C" { 11 | #endif 12 | 13 | 14 | #define TOPIC_NTP "/ext/ntp/%s/%s/request" 15 | #define TOPIC_NTP_REPLY "/ext/ntp/%s/%s/response" 16 | 17 | #define NTP_TIME_STR_MAX_LEN (20) 18 | 19 | int linkkit_ntp_time_request(void (*)(const char *ntp_offset_time_ms)); 20 | 21 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/impl_solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _LINKKIT_SOLO_LEGACY_H_ 6 | #define _LINKKIT_SOLO_LEGACY_H_ 7 | 8 | #include "linkkit_export.h" 9 | 10 | #define LINKKIT_SOLO_LEGACY_KEY_ID "id" 11 | #define LINKKIT_SOLO_LEGACY_KEY_CODE "code" 12 | #define LINKKIT_SOLO_LEGACY_KEY_DEVID "devid" 13 | #define LINKKIT_SOLO_LEGACY_KEY_SERVICEID "serviceid" 14 | #define LINKKIT_SOLO_LEGACY_KEY_PROPERTYID "propertyid" 15 | #define LINKKIT_SOLO_LEGACY_KEY_EVENTID "eventid" 16 | #define LINKKIT_SOLO_LEGACY_KEY_PAYLOAD "payload" 17 | #define LINKKIT_SOLO_LEGACY_KEY_CONFIG_ID "configId" 18 | #define LINKKIT_SOLO_LEGACY_KEY_CONFIG_SIZE "configSize" 19 | #define LINKKIT_SOLO_LEGACY_KEY_GET_TYPE "getType" 20 | #define LINKKIT_SOLO_LEGACY_KEY_SIGN "sign" 21 | #define LINKKIT_SOLO_LEGACY_KEY_SIGN_METHOD "signMethod" 22 | #define LINKKIT_SOLO_LEGACY_KEY_URL "url" 23 | #define LINKKIT_SOLO_LEGACY_KEY_VERSION "version" 24 | 25 | typedef struct { 26 | int msgid; 27 | handle_post_cb_fp_t callback; 28 | struct list_head linked_list; 29 | } linkkit_solo_upstream_callback_node_t; 30 | 31 | typedef struct { 32 | void *mutex; 33 | void *upstream_mutex; 34 | int is_started; 35 | int is_leaved; 36 | linkkit_ops_t *user_callback; 37 | void *user_context; 38 | handle_service_cota_callback_fp_t cota_callback; 39 | handle_service_fota_callback_fp_t fota_callback; 40 | struct list_head callback_list; 41 | } linkkit_solo_legacy_ctx_t; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/iotx_alcs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __IOTX_ALCS_CONFIG_H__ 6 | #define __IOTX_ALCS_CONFIG_H__ 7 | 8 | #if 0 9 | #ifndef ALCS_CLIENT_ENABLED 10 | #define ALCS_CLIENT_ENABLED (1) 11 | #endif 12 | #endif 13 | 14 | #ifndef ALCS_SERVER_ENABLED 15 | #define ALCS_SERVER_ENABLED (1) 16 | #endif 17 | 18 | #ifndef USE_ALCS_SECURE 19 | #define USE_ALCS_SECURE (1) 20 | #endif 21 | 22 | #ifndef KEYPREFIX_LEN 23 | #define KEYPREFIX_LEN (8) 24 | #endif 25 | 26 | #ifndef GROUPID_LEN 27 | #define GROUPID_LEN (8) 28 | #endif 29 | 30 | #endif /* #ifndef __IOTX_ALCS_CONFIG_H__ */ 31 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/iotx_cm_coap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _IOTX_CM_COAP_H_ 6 | #define _IOTX_CM_COAP_H_ 7 | #include "iotx_cm.h" 8 | #include "iotx_cm_internal.h" 9 | #include "coap_api.h" 10 | 11 | 12 | typedef struct { 13 | uint32_t token_num; 14 | void *user_data; 15 | char *topic; 16 | iotx_cm_data_handle_cb responce_cb; 17 | void *context; 18 | dlist_t linked_list; 19 | } coap_response_node_t; 20 | 21 | iotx_cm_connection_t *iotx_cm_open_coap(iotx_cm_init_param_t *params); 22 | 23 | #endif /* _LINKKIT_CM_H_ */ 24 | 25 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/iotx_cm_mqtt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef _IOTX_CM_MQTT_H_ 7 | #define _IOTX_CM_MQTT_H_ 8 | 9 | #include "iotx_cm.h" 10 | #include "iotx_cm_internal.h" 11 | 12 | 13 | typedef struct { 14 | uintptr_t packet_id; 15 | char * topic; 16 | void * user_data; 17 | iotx_mqtt_event_handle_func_fpt sub_state_cb; 18 | iotx_cm_data_handle_cb sub_recieve_cb; 19 | dlist_t linked_list; 20 | } mqtt_sub_node_t; 21 | 22 | iotx_cm_connection_t *iotx_cm_open_mqtt(iotx_cm_init_param_t *params); 23 | 24 | 25 | #endif /* _LINKKIT_CM_H_ */ 26 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/iotx_dm_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _IOTX_DM_CONFIG_H_ 8 | #define _IOTX_DM_CONFIG_H_ 9 | 10 | #define IOTX_DM_CLIENT_CONNECT_TIMEOUT_MS (10000) 11 | #define IOTX_DM_CLIENT_SUB_RETRY_MAX_COUNTS (3) 12 | #define IOTX_DM_CLIENT_SUB_TIMEOUT_MS (5000) 13 | #define IOTX_DM_CLIENT_REQUEST_TIMEOUT_MS (2000) 14 | #define IOTX_DM_CLIENT_KEEPALIVE_INTERVAL_MS (30000) 15 | 16 | #ifndef CONFIG_MQTT_TX_MAXLEN 17 | #define CONFIG_MQTT_TX_MAXLEN (1024) 18 | #endif 19 | 20 | #ifndef CONFIG_MQTT_RX_MAXLEN 21 | #define CONFIG_MQTT_RX_MAXLEN (1024) 22 | #endif 23 | 24 | #ifndef CONFIG_DISPATCH_QUEUE_MAXLEN 25 | #define CONFIG_DISPATCH_QUEUE_MAXLEN (50) 26 | #endif 27 | 28 | #ifndef CONFIG_DISPATCH_PACKET_MAXCOUNT 29 | #define CONFIG_DISPATCH_PACKET_MAXCOUNT (0) 30 | #endif 31 | 32 | #ifndef CONFIG_MSGCACHE_QUEUE_MAXLEN 33 | #define CONFIG_MSGCACHE_QUEUE_MAXLEN (50) 34 | #endif 35 | 36 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/dev_model/iotx_log_report.h: -------------------------------------------------------------------------------- 1 | void get_msgid(char *payload, int is_cloud); 2 | int check_target_msg(const char *input, int len); 3 | void send_permance_info(char *input, int input_len, char *comments, int report_format); 4 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_reset/dev_reset_api.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEV_RESET_API_H__ 2 | #define __DEV_RESET_API_H__ 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | 7 | typedef enum { 8 | IOTX_DEVRST_EVT_RECEIVED 9 | } iotx_devrst_evt_type_t; 10 | 11 | typedef struct { 12 | int msgid; 13 | char *payload; 14 | uint32_t payload_len; 15 | } iotx_devrst_evt_recv_msg_t; 16 | 17 | typedef void (*iotx_devrst_evt_handle_t)(iotx_devrst_evt_type_t evt, void *msg); 18 | 19 | /** 20 | * @brief report reset message to cloud. 21 | * 22 | * @param meta_info. device meta info, only product_key and device_name needed. 23 | * @param extended. reserved. 24 | * 25 | * @retval -1 : failure 26 | * @retval 0 : sucess 27 | */ 28 | int IOT_DevReset_Report(iotx_dev_meta_info_t *meta_info, iotx_devrst_evt_handle_t handle, void *extended); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_reset/dev_reset_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_RESET_INTERNAL_H_ 2 | #define _DEV_RESET_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "infra_config.h" 7 | #include "infra_types.h" 8 | #include "infra_defs.h" 9 | #include "infra_report.h" 10 | #include "dev_reset_internal.h" 11 | #include "dev_reset_wrapper.h" 12 | #include "dev_reset_api.h" 13 | #include "mqtt_api.h" 14 | 15 | #ifdef INFRA_LOG 16 | #include "infra_log.h" 17 | #define devrst_err(...) log_err("devrst", __VA_ARGS__) 18 | #define devrst_info(...) log_info("devrst", __VA_ARGS__) 19 | #define devrst_debug(...) log_debug("devrst", __VA_ARGS__) 20 | #else 21 | #define devrst_info(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 22 | #define devrst_err(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 23 | #define devrst_debug(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 24 | #endif 25 | 26 | #ifdef INFRA_MEM_STATS 27 | #include "infra_mem_stats.h" 28 | #define devrst_malloc(size) LITE_malloc(size, MEM_MAGIC, "devrst") 29 | #define devrst_free(ptr) LITE_free(ptr) 30 | #else 31 | #define devrst_malloc(size) HAL_Malloc(size) 32 | #define devrst_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 33 | #endif 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_reset/dev_reset_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_RESET_WRAPPER_H_ 2 | #define _DEV_RESET_WRAPPER_H_ 3 | 4 | int HAL_Snprintf(char *str, const int len, const char *fmt, ...); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_sign/dev_sign_api.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_SIGN_H_ 2 | #define _DEV_SIGN_H_ 3 | 4 | #include "dev_sign_internal.h" 5 | 6 | typedef struct { 7 | char hostname[DEV_SIGN_HOSTNAME_MAXLEN]; 8 | uint16_t port; 9 | char clientid[DEV_SIGN_CLIENT_ID_MAXLEN]; 10 | char username[DEV_SIGN_USERNAME_MAXLEN]; 11 | char password[DEV_SIGN_PASSWORD_MAXLEN]; 12 | } iotx_sign_mqtt_t; 13 | 14 | int32_t IOT_Sign_MQTT(iotx_mqtt_region_types_t region, iotx_dev_meta_info_t *meta, iotx_sign_mqtt_t *signout); 15 | 16 | #endif 17 | 18 | 19 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_sign/dev_sign_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_SIGN_CONFIG_H_ 2 | #define _DEV_SIGN_CONFIG_H_ 3 | 4 | #define DEV_SIGN_SOURCE_MAXLEN (200) 5 | #define DEV_SIGN_HOSTNAME_MAXLEN (64) 6 | #define DEV_SIGN_CLIENT_ID_MAXLEN (200) 7 | #define DEV_SIGN_USERNAME_MAXLEN (64) 8 | #define DEV_SIGN_PASSWORD_MAXLEN (65) 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_sign/dev_sign_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_SIGN_INTERNAL_H_ 2 | #define _DEV_SIGN_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "infra_config.h" 7 | #include "infra_defs.h" 8 | #include "dev_sign_config.h" 9 | #include "dev_sign_api.h" 10 | #include "dev_sign_wrapper.h" 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /iotkit-embedded/dev_sign/dev_sign_wrapper.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "infra_types.h" 4 | #include "infra_defs.h" 5 | -------------------------------------------------------------------------------- /iotkit-embedded/dynamic_register/dynreg_api.h: -------------------------------------------------------------------------------- 1 | #ifndef _DYNREG_API_H_ 2 | #define _DYNREG_API_H_ 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | 7 | int32_t IOT_Dynamic_Register(iotx_http_region_types_t region, iotx_dev_meta_info_t *meta); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /iotkit-embedded/dynamic_register/dynreg_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _DYNREG_INTERNAL_H_ 2 | #define _DYNREG_INTERNAL_H_ 3 | 4 | #include "dynreg_wrapper.h" 5 | 6 | #ifdef INFRA_LOG 7 | #include "infra_log.h" 8 | #define dynreg_info(...) log_info("dynreg", __VA_ARGS__) 9 | #define dynreg_err(...) log_err("dynreg", __VA_ARGS__) 10 | #define dynreg_dbg(...) log_debug("dynreg", __VA_ARGS__) 11 | #else 12 | #define dynreg_info(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 13 | #define dynreg_err(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 14 | #define dynreg_dbg(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 15 | #endif 16 | 17 | #ifdef INFRA_MEM_STATS 18 | #include "infra_mem_stats.h" 19 | #define dynreg_malloc(size) LITE_malloc(size, MEM_MAGIC, "dynreg") 20 | #define dynreg_free(ptr) LITE_free(ptr) 21 | #else 22 | #define dynreg_malloc(size) HAL_Malloc(size) 23 | #define dynreg_free(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 24 | #endif 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /iotkit-embedded/dynamic_register/dynreg_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _DYNREG_WRAPPER_H_ 2 | #define _DYNREG_WRAPPER_H_ 3 | 4 | #include "infra_types.h" 5 | 6 | void *HAL_Malloc(uint32_t size); 7 | void HAL_Free(void *ptr); 8 | void HAL_Printf(const char *fmt, ...); 9 | int HAL_Snprintf(char *str, const int len, const char *fmt, ...); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /iotkit-embedded/http/http_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #ifndef __HTTP_DEBUG_H__ 9 | #define __HTTP_DEBUG_H__ 10 | 11 | #ifdef INFRA_LOG 12 | #include "infra_log.h" 13 | #define http_emerg(...) log_emerg("HTTP", __VA_ARGS__) 14 | #define http_crit(...) log_crit("HTTP", __VA_ARGS__) 15 | #define http_err(...) log_err("HTTP", __VA_ARGS__) 16 | #define http_warning(...) log_warning("HTTP", __VA_ARGS__) 17 | #define http_info(...) log_info("HTTP", __VA_ARGS__) 18 | #define http_debug(...) log_debug("HTTP", __VA_ARGS__) 19 | #else 20 | #define http_emerg(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 21 | #define http_crit(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 22 | #define http_err(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 23 | #define http_warning(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 24 | #define http_info(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 25 | #define http_debug(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 26 | #endif 27 | 28 | 29 | #endif /* __HTTP_DEBUG_H__ */ 30 | -------------------------------------------------------------------------------- /iotkit-embedded/http/http_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _HTTP_WRAPPER_H 2 | #define _HTTP_WRAPPER_H 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | #include "wrappers_defs.h" 7 | 8 | void *HAL_Malloc(uint32_t size); 9 | void HAL_Free(void *ptr); 10 | void HAL_Printf(const char *fmt, ...); 11 | int HAL_Snprintf(char *str, const int len, const char *fmt, ...); 12 | uint64_t HAL_UptimeMs(void); 13 | void HAL_SleepMs(uint32_t ms); 14 | 15 | #endif /* #ifndef _HTTP_WRAPPER_H */ 16 | -------------------------------------------------------------------------------- /iotkit-embedded/http2/http2_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _HTTP2_CONFIG_H 6 | #define _HTTP2_CONFIG_H 7 | 8 | /* maximum packet len in one http2 frame */ 9 | #ifndef FS_UPLOAD_PACKET_LEN 10 | #define FS_UPLOAD_PACKET_LEN 10240 /* must < 16384 */ 11 | #endif 12 | 13 | /* maximum content len of the http2 request */ 14 | #ifndef FS_UPLOAD_PART_LEN 15 | #define FS_UPLOAD_PART_LEN (1024 * 1024 * 4) /* 100KB ~ 100MB */ 16 | #endif 17 | 18 | 19 | #endif /* #ifdef _HTTP2_CONFIG_H */ 20 | 21 | -------------------------------------------------------------------------------- /iotkit-embedded/http2/http2_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __HTTP2_WRAPPER_H__ 6 | #define __HTTP2_WRAPPER_H__ 7 | 8 | #include "infra_types.h" 9 | #include "infra_defs.h" 10 | #include "wrappers_defs.h" 11 | 12 | extern void HAL_Printf(const char *fmt, ...); 13 | extern void HAL_SleepMs(uint32_t ms); 14 | 15 | extern void *HAL_Malloc(uint32_t size); 16 | extern void *HAL_Realloc(void *ptr, uint32_t size); 17 | extern void HAL_Free(void *ptr); 18 | 19 | extern void *HAL_MutexCreate(void); 20 | extern void HAL_MutexDestroy(void *mutex); 21 | extern void HAL_MutexLock(void *mutex); 22 | extern void HAL_MutexUnlock(void *mutex); 23 | 24 | extern void *HAL_SemaphoreCreate(void); 25 | extern void HAL_SemaphoreDestroy(void *sem); 26 | extern void HAL_SemaphorePost(void *sem); 27 | extern int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms); 28 | 29 | extern int HAL_ThreadCreate( 30 | void **thread_handle, 31 | void *(*work_routine)(void *), 32 | void *arg, 33 | hal_os_thread_param_t *hal_os_thread_param, 34 | int *stack_used); 35 | extern void HAL_ThreadDetach(void *thread_handle); 36 | extern void HAL_ThreadDelete(void *thread_handle); 37 | 38 | #ifdef FS_ENABLED 39 | typedef enum { 40 | HAL_SEEK_SET, 41 | HAL_SEEK_CUR, 42 | HAL_SEEK_END 43 | } hal_fs_seek_type_t; 44 | 45 | extern void *HAL_Fopen(const char *path, const char *mode); 46 | extern uint32_t HAL_Fread(void *buff, uint32_t size, uint32_t count, void *stream); 47 | extern uint32_t HAL_Fwrite(const void *ptr, uint32_t size, uint32_t count, void *stream); 48 | extern int HAL_Fseek(void *stream, long offset, int framewhere); 49 | extern int HAL_Fclose(void *stream); 50 | extern long HAL_Ftell(void *stream); 51 | #endif /* #ifdef FS_ENABLED */ 52 | 53 | #endif /* #ifndef __HTTP2_WRAPPER_H__ */ 54 | 55 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _INFRA_CONFIG_H_ 2 | #define _INFRA_CONFIG_H_ 3 | 4 | #include "sdkconfig.h" 5 | 6 | #define PLATFORM_HAS_STDINT 7 | #define PLATFORM_HAS_DYNMEM 8 | #define PLATFORM_HAS_OS 9 | #define INFRA_STRING 10 | #define INFRA_NET 11 | #define INFRA_LIST 12 | //#define INFRA_LOG_NETWORK_PAYLOAD 13 | #define INFRA_LOG 14 | //#define INFRA_LOG_ALL_MUTED 15 | //#define INFRA_LOG_MUTE_FLW 16 | //#define INFRA_LOG_MUTE_DBG 17 | //#define INFRA_LOG_MUTE_INF 18 | //#define INFRA_LOG_MUTE_WRN 19 | //#define INFRA_LOG_MUTE_ERR 20 | //#define INFRA_LOG_MUTE_CRT 21 | #define INFRA_TIMER 22 | #define INFRA_JSON_PARSER 23 | #define INFRA_CJSON 24 | #define INFRA_MD5 25 | #define INFRA_SHA1 26 | #define INFRA_SHA256 27 | #define INFRA_REPORT 28 | #define INFRA_HTTPC 29 | #define INFRA_COMPAT 30 | #define INFRA_CLASSIC 31 | #define DEV_SIGN 32 | #define MQTT_COMM_ENABLED 33 | #define MQTT_DEFAULT_IMPL 34 | #if CONFIG_MQTT_DIRECT 35 | #define MQTT_DIRECT 36 | #else 37 | #define MQTT_PRE_AUTH 38 | #define INFRA_PREAUTH 39 | #endif 40 | #define DEVICE_MODEL_CLASSIC 41 | //#define LOG_REPORT_TO_CLOUD 42 | #define DEVICE_MODEL_ENABLED 43 | #if CONFIG_DEVICE_MODEL_GATEWAY 44 | #define DEVICE_MODEL_GATEWAY 45 | #endif 46 | #if CONFIG_DEVICE_ALCS_ENABLE 47 | #define ALCS_ENABLED 48 | #endif 49 | #if CONFIG_DYNAMIC_REGISTER 50 | #define DYNAMIC_REGISTER 51 | #endif 52 | #define DEVICE_MODEL_SUBDEV_OTA 53 | #define DEVICE_MODEL_SHADOW 54 | #define HAL_KV 55 | #define SUPPORT_TLS 56 | #if defined(SUPPORT_TLS) && CONFIG_SUPPORT_TCP 57 | #define SUPPORT_TCP 58 | #endif 59 | #define HAL_CRYPTO 60 | #define HAL_UDP 61 | //#define COAP_DTLS_SUPPORT 62 | #define OTA_ENABLED 63 | //#define COAP_COMM_ENABLED 64 | #define COAP_PACKET 65 | #define COAP_CLIENT 66 | #define COAP_SERVER 67 | #define DEV_RESET 68 | #define HTTP_COMM_ENABLED 69 | #define HTTP2_COMM_ENABLED 70 | #define FS_ENABLED 71 | #define AWSS_SUPPORT_APLIST 72 | #define AWSS_SUPPORT_ADHA 73 | #define AWSS_FRAMEWORKS 74 | #define WIFI_PROVISION_ENABLED 75 | #define AWSS_SUPPORT_SMARTCONFIG_WPS 76 | #define AWSS_SUPPORT_SMARTCONFIG 77 | #define AWSS_SUPPORT_ZEROCONFIG 78 | #define AWSS_SUPPORT_AHA 79 | #define AWSS_SUPPORT_DEV_AP 80 | #define DEV_BIND_ENABLED 81 | #ifdef CONFIG_SUPPORT_SECURITY_OTA 82 | #define SUPPORT_SECURITY_OTA 83 | #endif 84 | #endif 85 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_defs.c: -------------------------------------------------------------------------------- 1 | 2 | #include "infra_config.h" 3 | #include "infra_types.h" 4 | #include "infra_defs.h" 5 | 6 | const char * g_infra_mqtt_domain[IOTX_MQTT_DOMAIN_NUMBER] = { 7 | "iot-as-mqtt.cn-shanghai.aliyuncs.com", /* Shanghai */ 8 | "iot-as-mqtt.ap-southeast-1.aliyuncs.com", /* Singapore */ 9 | "iot-as-mqtt.ap-northeast-1.aliyuncs.com", /* Japan */ 10 | "iot-as-mqtt.us-west-1.aliyuncs.com", /* America */ 11 | "iot-as-mqtt.eu-central-1.aliyuncs.com", /* Germany */ 12 | NULL, /* Custom */ 13 | }; 14 | 15 | const char *g_infra_http_domain[IOTX_HTTP_DOMAIN_NUMBER] = { 16 | "iot-auth.cn-shanghai.aliyuncs.com", /* Shanghai */ 17 | "iot-auth.ap-southeast-1.aliyuncs.com", /* Singapore */ 18 | "iot-auth.ap-northeast-1.aliyuncs.com", /* Japan */ 19 | "iot-auth.us-west-1.aliyuncs.com", /* America */ 20 | "iot-auth.eu-central-1.aliyuncs.com", /* Germany */ 21 | NULL, /* Custom */ 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #ifndef _INFRA_MD5_H_ 9 | #define _INFRA_MD5_H_ 10 | 11 | #include "infra_types.h" 12 | 13 | typedef struct { 14 | uint32_t total[2]; /*!< number of bytes processed */ 15 | uint32_t state[4]; /*!< intermediate digest state */ 16 | unsigned char buffer[64]; /*!< data block being processed */ 17 | } iot_md5_context; 18 | 19 | /** 20 | * \brief Initialize MD5 context 21 | * 22 | * \param ctx MD5 context to be initialized 23 | */ 24 | void utils_md5_init(iot_md5_context *ctx); 25 | 26 | /** 27 | * \brief Clear MD5 context 28 | * 29 | * \param ctx MD5 context to be cleared 30 | */ 31 | void utils_md5_free(iot_md5_context *ctx); 32 | 33 | /** 34 | * \brief Clone (the state of) an MD5 context 35 | * 36 | * \param dst The destination context 37 | * \param src The context to be cloned 38 | */ 39 | void utils_md5_clone(iot_md5_context *dst, 40 | const iot_md5_context *src); 41 | 42 | /** 43 | * \brief MD5 context setup 44 | * 45 | * \param ctx context to be initialized 46 | */ 47 | void utils_md5_starts(iot_md5_context *ctx); 48 | 49 | /** 50 | * \brief MD5 process buffer 51 | * 52 | * \param ctx MD5 context 53 | * \param input buffer holding the data 54 | * \param ilen length of the input data 55 | */ 56 | void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, uint32_t ilen); 57 | 58 | /** 59 | * \brief MD5 final digest 60 | * 61 | * \param ctx MD5 context 62 | * \param output MD5 checksum result 63 | */ 64 | void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]); 65 | 66 | /* Internal use */ 67 | void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]); 68 | 69 | /** 70 | * \brief Output = MD5( input buffer ) 71 | * 72 | * \param input buffer holding the data 73 | * \param ilen length of the input data 74 | * \param output MD5 checksum result 75 | */ 76 | void utils_md5(const unsigned char *input, uint32_t ilen, unsigned char output[16]); 77 | 78 | void utils_hmac_md5(const char *msg, int msg_len, char *digest, const char *key, int key_len); 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _INFRA_NET_H_ 6 | #define _INFRA_NET_H_ 7 | 8 | #include "infra_types.h" 9 | 10 | /** 11 | * @brief The structure of network connection(TCP or SSL). 12 | * The user has to allocate memory for this structure. 13 | */ 14 | 15 | struct utils_network; 16 | typedef struct utils_network utils_network_t, *utils_network_pt; 17 | 18 | struct utils_network { 19 | const char *pHostAddress; 20 | uint16_t port; 21 | uint16_t ca_crt_len; 22 | 23 | /**< NULL, TCP connection; NOT NULL, SSL connection */ 24 | const char *ca_crt; 25 | /**< NOT NULL,iTLS connection*/ 26 | char *product_key; 27 | /**< connection handle: 0, NOT connection; NOT 0, handle of the connection */ 28 | uintptr_t handle; 29 | 30 | /**< Read data from server function pointer. */ 31 | int (*read)(utils_network_pt, char *, uint32_t, uint32_t); 32 | 33 | /**< Send data to server function pointer. */ 34 | int (*write)(utils_network_pt, const char *, uint32_t, uint32_t); 35 | 36 | /**< Disconnect the network */ 37 | int (*disconnect)(utils_network_pt); 38 | 39 | /**< Establish the network */ 40 | int (*connect)(utils_network_pt); 41 | }; 42 | 43 | int utils_net_read(utils_network_pt pNetwork, char *buffer, uint32_t len, uint32_t timeout_ms); 44 | int utils_net_write(utils_network_pt pNetwork, const char *buffer, uint32_t len, uint32_t timeout_ms); 45 | int iotx_net_disconnect(utils_network_pt pNetwork); 46 | int iotx_net_connect(utils_network_pt pNetwork); 47 | int iotx_net_init(utils_network_pt pNetwork, const char *host, uint16_t port, const char *ca_crt); 48 | #ifdef SUPPORT_TCP 49 | int iotx_net_tcp_init(utils_network_pt pNetwork, const char *host, uint16_t port, const char *ca_crt); 50 | #endif 51 | #endif /* IOTX_COMMON_NET_H */ 52 | 53 | 54 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_preauth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __INFRA_PREAUTH__ 6 | #define __INFRA_PREAUTH__ 7 | 8 | #include "infra_defs.h" 9 | #include "infra_types.h" 10 | #include "dev_sign_api.h" 11 | 12 | #ifdef INFRA_LOG 13 | #include "infra_log.h" 14 | #define preauth_err(...) log_err("preauth", __VA_ARGS__) 15 | #define preauth_info(...) log_info("preauth", __VA_ARGS__) 16 | #define preauth_debug(...) log_debug("preauth", __VA_ARGS__) 17 | #else 18 | #define preauth_err(...) 19 | #define preauth_info(...) 20 | #define preauth_debug(...) 21 | #endif 22 | 23 | int preauth_get_connection_info(iotx_mqtt_region_types_t region, iotx_dev_meta_info_t *dev_meta, 24 | const char *sign, const char *device_id, iotx_sign_mqtt_t *preauth_output); 25 | 26 | #endif /* #ifndef __INFRA_PREAUTH__ */ -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_redirect_region.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _INFRA_REDIRECT_REGION_H_ 6 | #define _INFRA_REDIRECT_REGION_H_ 7 | 8 | #include "infra_types.h" 9 | 10 | int iotx_redirect_region_subscribe(void); 11 | int iotx_redirect_set_flag(int flag); 12 | int iotx_redirect_get_flag(void); 13 | int iotx_redirect_get_iotId_iotToken(char *iot_id,char *iot_token,char *host, uint16_t *pport); 14 | 15 | #endif -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #ifndef _INFRA_SHA1_H_ 9 | #define _INFRA_SHA1_H_ 10 | 11 | #include "infra_types.h" 12 | 13 | #define SHA1_DIGEST_SIZE (20) 14 | 15 | /** 16 | * \brief SHA-1 context structure 17 | */ 18 | typedef struct { 19 | uint32_t total[2]; /*!< number of bytes processed */ 20 | uint32_t state[5]; /*!< intermediate digest state */ 21 | unsigned char buffer[64]; /*!< data block being processed */ 22 | } iot_sha1_context; 23 | 24 | /** 25 | * \brief Initialize SHA-1 context 26 | * 27 | * \param ctx SHA-1 context to be initialized 28 | */ 29 | void utils_sha1_init(iot_sha1_context *ctx); 30 | 31 | /** 32 | * \brief Clear SHA-1 context 33 | * 34 | * \param ctx SHA-1 context to be cleared 35 | */ 36 | void utils_sha1_free(iot_sha1_context *ctx); 37 | 38 | /** 39 | * \brief Clone (the state of) a SHA-1 context 40 | * 41 | * \param dst The destination context 42 | * \param src The context to be cloned 43 | */ 44 | void utils_sha1_clone(iot_sha1_context *dst, 45 | const iot_sha1_context *src); 46 | 47 | /** 48 | * \brief SHA-1 context setup 49 | * 50 | * \param ctx context to be initialized 51 | */ 52 | void utils_sha1_starts(iot_sha1_context *ctx); 53 | 54 | /** 55 | * \brief SHA-1 process buffer 56 | * 57 | * \param ctx SHA-1 context 58 | * \param input buffer holding the data 59 | * \param ilen length of the input data 60 | */ 61 | void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, uint32_t ilen); 62 | 63 | /** 64 | * \brief SHA-1 final digest 65 | * 66 | * \param ctx SHA-1 context 67 | * \param output SHA-1 checksum result 68 | */ 69 | void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20]); 70 | 71 | /* Internal use */ 72 | void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64]); 73 | 74 | /** 75 | * \brief Output = SHA-1( input buffer ) 76 | * 77 | * \param input buffer holding the data 78 | * \param ilen length of the input data 79 | * \param output SHA-1 checksum result 80 | */ 81 | void utils_sha1(const unsigned char *input, uint32_t ilen, unsigned char output[20]); 82 | 83 | void utils_hmac_sha1(const char *msg, int msg_len, char *digest, const char *key, int key_len); 84 | void utils_hmac_sha1_hex(const char *msg, int msg_len, char *digest, const char *key, int key_len); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_sha256.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _IOTX_COMMON_SHA256_H_ 6 | #define _IOTX_COMMON_SHA256_H_ 7 | 8 | #include 9 | 10 | #define SHA256_DIGEST_LENGTH (32) 11 | #define SHA256_BLOCK_LENGTH (64) 12 | #define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) 13 | #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 14 | 15 | /** 16 | * \brief SHA-256 context structure 17 | */ 18 | typedef struct { 19 | uint32_t total[2]; /*!< number of bytes processed */ 20 | uint32_t state[8]; /*!< intermediate digest state */ 21 | unsigned char buffer[64]; /*!< data block being processed */ 22 | int is224; /*!< 0 => SHA-256, else SHA-224 */ 23 | } iot_sha256_context; 24 | 25 | typedef union { 26 | char sptr[8]; 27 | uint64_t lint; 28 | } u_retLen; 29 | 30 | /** 31 | * \brief Initialize SHA-256 context 32 | * 33 | * \param ctx SHA-256 context to be initialized 34 | */ 35 | void utils_sha256_init(iot_sha256_context *ctx); 36 | 37 | /** 38 | * \brief Clear SHA-256 context 39 | * 40 | * \param ctx SHA-256 context to be cleared 41 | */ 42 | void utils_sha256_free(iot_sha256_context *ctx); 43 | 44 | 45 | /** 46 | * \brief SHA-256 context setup 47 | * 48 | * \param ctx context to be initialized 49 | */ 50 | void utils_sha256_starts(iot_sha256_context *ctx); 51 | 52 | /** 53 | * \brief SHA-256 process buffer 54 | * 55 | * \param ctx SHA-256 context 56 | * \param input buffer holding the data 57 | * \param ilen length of the input data 58 | */ 59 | void utils_sha256_update(iot_sha256_context *ctx, const unsigned char *input, uint32_t ilen); 60 | 61 | /** 62 | * \brief SHA-256 final digest 63 | * 64 | * \param ctx SHA-256 context 65 | * \param output SHA-256 checksum result 66 | */ 67 | void utils_sha256_finish(iot_sha256_context *ctx, uint8_t output[32]); 68 | 69 | /* Internal use */ 70 | void utils_sha256_process(iot_sha256_context *ctx, const unsigned char data[64]); 71 | 72 | /** 73 | * \brief Output = SHA-256( input buffer ) 74 | * 75 | * \param input buffer holding the data 76 | * \param ilen length of the input data 77 | * \param output SHA-256 checksum result 78 | */ 79 | void utils_sha256(const uint8_t *input, uint32_t ilen, uint8_t output[32]); 80 | 81 | void utils_hmac_sha256(const uint8_t *msg, uint32_t msg_len, const uint8_t *key, uint32_t key_len, uint8_t output[32]); 82 | 83 | #endif 84 | 85 | 86 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_string.h: -------------------------------------------------------------------------------- 1 | #ifndef _INFRA_STRING_H_ 2 | #define _INFRA_STRING_H_ 3 | 4 | #include "infra_types.h" 5 | 6 | int8_t infra_hex2char(uint8_t hex); 7 | void infra_hex2str(uint8_t *input, uint16_t input_len, char *output); 8 | void infra_int2str(uint32_t input, char output[10]); 9 | char *infra_strtok(char *str, const char *delim); 10 | int infra_randstr(char *random, int length); 11 | void LITE_hexstr_convert(char *input, int input_len, unsigned char *output, int output_len); 12 | int infra_str2int(const char *input, int *val); 13 | void LITE_hexbuf_convert(unsigned char *digest, char *out, int in_len, int uppercase); 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_timer.c: -------------------------------------------------------------------------------- 1 | #include "infra_config.h" 2 | 3 | #ifdef INFRA_TIMER 4 | /* 5 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 6 | */ 7 | #include "infra_types.h" 8 | #include "infra_timer.h" 9 | 10 | uint64_t HAL_UptimeMs(void); 11 | 12 | void iotx_time_start(iotx_time_t *timer) 13 | { 14 | if (!timer) { 15 | return; 16 | } 17 | 18 | timer->time = HAL_UptimeMs(); 19 | } 20 | 21 | uint32_t utils_time_spend(iotx_time_t *start) 22 | { 23 | uint32_t now, res; 24 | 25 | if (!start) { 26 | return 0; 27 | } 28 | 29 | now = HAL_UptimeMs(); 30 | res = now - start->time; 31 | return res; 32 | } 33 | 34 | uint32_t iotx_time_left(iotx_time_t *end) 35 | { 36 | uint32_t now, res; 37 | 38 | if (!end) { 39 | return 0; 40 | } 41 | 42 | if (utils_time_is_expired(end)) { 43 | return 0; 44 | } 45 | 46 | now = HAL_UptimeMs(); 47 | res = end->time - now; 48 | return res; 49 | } 50 | 51 | uint32_t utils_time_is_expired(iotx_time_t *timer) 52 | { 53 | uint32_t cur_time; 54 | 55 | if (!timer) { 56 | return 1; 57 | } 58 | 59 | cur_time = HAL_UptimeMs(); 60 | /* 61 | * WARNING: Do NOT change the following code until you know exactly what it do! 62 | * 63 | * check whether it reach destination time or not. 64 | */ 65 | if ((cur_time - timer->time) < (UINT32_MAX / 2)) { 66 | return 1; 67 | } else { 68 | return 0; 69 | } 70 | } 71 | 72 | void iotx_time_init(iotx_time_t *timer) 73 | { 74 | if (!timer) { 75 | return; 76 | } 77 | 78 | timer->time = 0; 79 | } 80 | 81 | void utils_time_countdown_ms(iotx_time_t *timer, uint32_t millisecond) 82 | { 83 | if (!timer) { 84 | return; 85 | } 86 | 87 | timer->time = HAL_UptimeMs() + millisecond; 88 | } 89 | 90 | uint32_t utils_time_get_ms(void) 91 | { 92 | return HAL_UptimeMs(); 93 | } 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #ifndef _INFRA_TIMER_H_ 9 | #define _INFRA_TIMER_H_ 10 | 11 | #include "infra_types.h" 12 | 13 | typedef struct { 14 | uint32_t time; 15 | } iotx_time_t; 16 | 17 | 18 | void iotx_time_start(iotx_time_t *timer); 19 | 20 | uint32_t utils_time_spend(iotx_time_t *start); 21 | 22 | uint32_t iotx_time_left(iotx_time_t *end); 23 | 24 | uint32_t utils_time_is_expired(iotx_time_t *timer); 25 | 26 | void iotx_time_init(iotx_time_t *timer); 27 | 28 | void utils_time_countdown_ms(iotx_time_t *timer, uint32_t millisecond); 29 | 30 | uint32_t utils_time_get_ms(void); 31 | 32 | #endif /* _IOTX_COMMON_TIMER_H_ */ 33 | 34 | 35 | -------------------------------------------------------------------------------- /iotkit-embedded/infra/infra_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _INFRA_TYPES_H_ 2 | #define _INFRA_TYPES_H_ 3 | 4 | #include 5 | #include "infra_config.h" 6 | 7 | #define IOT_TRUE (1) /* indicate boolean value true */ 8 | #define IOT_FALSE (0) /* indicate boolean value false */ 9 | 10 | #if !defined(PLATFORM_HAS_STDINT) 11 | 12 | typedef unsigned char uint8_t; 13 | typedef signed char int8_t; 14 | typedef unsigned short uint16_t; 15 | typedef signed short int16_t; 16 | typedef unsigned int uint32_t; 17 | typedef signed int int32_t; 18 | typedef unsigned long int uint64_t; 19 | typedef signed long int int64_t; 20 | typedef unsigned int uintptr_t; 21 | 22 | #else 23 | 24 | #include 25 | 26 | #endif /* #if !defined(PLATFORM_HAS_STDINT) */ 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /iotkit-embedded/mqtt/MQTTPublish.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MQTTPUBLISH_H_ 6 | #define MQTTPUBLISH_H_ 7 | 8 | #if !defined(DLLImport) 9 | #define DLLImport 10 | #endif 11 | #if !defined(DLLExport) 12 | #define DLLExport 13 | #endif 14 | 15 | DLLExport int MQTTSerialize_publish(unsigned char *buf, int buflen, unsigned char dup, int qos, unsigned char retained, 16 | unsigned short packetid, 17 | MQTTString topicName, unsigned char *payload, int payloadlen); 18 | 19 | DLLExport int MQTTDeserialize_publish(unsigned char *dup, int *qos, unsigned char *retained, unsigned short *packetid, 20 | MQTTString *topicName, 21 | unsigned char **payload, int *payloadlen, unsigned char *buf, int len); 22 | 23 | /* DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid); */ 24 | DLLExport int MQTTSerialize_pubrel(unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid); 25 | DLLExport int MQTTSerialize_pubcomp(unsigned char *buf, int buflen, unsigned short packetid); 26 | 27 | #endif /* MQTTPUBLISH_H_ */ 28 | 29 | 30 | -------------------------------------------------------------------------------- /iotkit-embedded/mqtt/MQTTSubscribe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MQTTSUBSCRIBE_H_ 6 | #define MQTTSUBSCRIBE_H_ 7 | 8 | #if !defined(DLLImport) 9 | #define DLLImport 10 | #endif 11 | #if !defined(DLLExport) 12 | #define DLLExport 13 | #endif 14 | 15 | DLLExport int MQTTSerialize_subscribe(unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid, 16 | int count, MQTTString topicFilters[], int requestedQoSs[]); 17 | 18 | DLLExport int MQTTDeserialize_subscribe(unsigned char *dup, unsigned short *packetid, 19 | int maxcount, int *count, MQTTString topicFilters[], int requestedQoSs[], unsigned char *buf, int len); 20 | 21 | DLLExport int MQTTSerialize_suback(unsigned char *buf, int buflen, unsigned short packetid, int count, 22 | int *grantedQoSs); 23 | 24 | DLLExport int MQTTDeserialize_suback(unsigned short *packetid, int maxcount, int *count, int grantedQoSs[], 25 | unsigned char *buf, int len); 26 | 27 | 28 | #endif /* MQTTSUBSCRIBE_H_ */ 29 | 30 | 31 | -------------------------------------------------------------------------------- /iotkit-embedded/mqtt/MQTTUnsubscribe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MQTTUNSUBSCRIBE_H_ 6 | #define MQTTUNSUBSCRIBE_H_ 7 | 8 | #if !defined(DLLImport) 9 | #define DLLImport 10 | #endif 11 | #if !defined(DLLExport) 12 | #define DLLExport 13 | #endif 14 | 15 | DLLExport int MQTTSerialize_unsubscribe(unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid, 16 | int count, MQTTString topicFilters[]); 17 | 18 | DLLExport int MQTTDeserialize_unsubscribe(unsigned char *dup, unsigned short *packetid, int max_count, int *count, 19 | MQTTString topicFilters[], 20 | unsigned char *buf, int len); 21 | 22 | DLLExport int MQTTSerialize_unsuback(unsigned char *buf, int buflen, unsigned short packetid); 23 | 24 | DLLExport int MQTTDeserialize_unsuback(unsigned short *packetid, unsigned char *buf, int len); 25 | 26 | #endif /* MQTTUNSUBSCRIBE_H_ */ 27 | 28 | 29 | -------------------------------------------------------------------------------- /iotkit-embedded/mqtt/mqtt_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __IOTX_MQTT_INTERNAL_H__ 6 | #define __IOTX_MQTT_INTERNAL_H__ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "infra_types.h" 14 | #include "infra_defs.h" 15 | #include "infra_string.h" 16 | #include "infra_list.h" 17 | #include "infra_log.h" 18 | #include "infra_report.h" 19 | #include "infra_net.h" 20 | #include "infra_sha256.h" 21 | 22 | #include "dev_sign_api.h" 23 | #include "mqtt_wrapper.h" 24 | #include "iotx_mqtt_config.h" 25 | #include "iotx_mqtt_client.h" 26 | 27 | #include "MQTTPacket.h" 28 | 29 | #ifdef INFRA_LOG 30 | #include "infra_log.h" 31 | #define mqtt_emerg(...) log_emerg("MQTT", __VA_ARGS__) 32 | #define mqtt_crit(...) log_crit("MQTT", __VA_ARGS__) 33 | #define mqtt_err(...) log_err("MQTT", __VA_ARGS__) 34 | #define mqtt_warning(...) log_warning("MQTT", __VA_ARGS__) 35 | #define mqtt_info(...) log_info("MQTT", __VA_ARGS__) 36 | #define mqtt_debug(...) log_debug("MQTT", __VA_ARGS__) 37 | #else 38 | #define mqtt_emerg(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 39 | #define mqtt_crit(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 40 | #define mqtt_err(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 41 | #define mqtt_warning(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 42 | #define mqtt_info(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 43 | #define mqtt_debug(...) do{HAL_Printf(__VA_ARGS__);HAL_Printf("\r\n");}while(0) 44 | #endif 45 | 46 | #endif /* __IOTX_MQTT_INTERNAL_H__ */ 47 | 48 | -------------------------------------------------------------------------------- /iotkit-embedded/ota/iotx_ota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __IOTX_OTA_H__ 6 | #define __IOTX_OTA_H__ 7 | 8 | int iotx_ota_get_config(void *handle, const char *configScope, const char *getType, 9 | const char *attributeKeys); 10 | 11 | int iotx_req_image(void *handle, const char *version); 12 | 13 | #endif /* #ifndef __IOTX_OTA_H__ */ 14 | 15 | 16 | -------------------------------------------------------------------------------- /iotkit-embedded/ota/iotx_ota_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __IOTX_OTA_CONFIG_H__ 6 | #define __IOTX_OTA_CONFIG_H__ 7 | 8 | #ifndef OTA_SIGNAL_CHANNEL 9 | #define OTA_SIGNAL_CHANNEL (1) 10 | #endif 11 | 12 | #endif /* __IOTX_OTA_CONFIG_H__ */ 13 | 14 | 15 | -------------------------------------------------------------------------------- /iotkit-embedded/ota/ota_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _OTA_WRAPPER_H_ 2 | #define _OTA_WRAPPER_H_ 3 | 4 | #include "infra_types.h" 5 | 6 | void *HAL_Malloc(uint32_t size); 7 | void HAL_Free(void *ptr); 8 | void HAL_Printf(const char *fmt, ...); 9 | int HAL_Snprintf(char *str, const int len, const char *fmt, ...); 10 | 11 | int HAL_SetProductKey(char *product_key); 12 | int HAL_SetDeviceName(char *device_name); 13 | int HAL_SetDeviceSecret(char *device_secret); 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/dev_ap/awss_dev_ap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_DEV_AP_H__ 6 | #define __AWSS_DEV_AP_H__ 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" 10 | { 11 | #endif 12 | 13 | int awss_dev_ap_stop(void); 14 | int awss_dev_ap_start(void); 15 | int wifimgr_process_dev_ap_switchap_request(void *ctx, void *resource, void *remote, void *request); 16 | 17 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/frameworks/aplist/awss_aplist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_APLIST_H__ 6 | #define __AWSS_APLIST_H__ 7 | 8 | #include 9 | #include "os.h" 10 | #include "zconfig_protocol.h" 11 | 12 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 13 | extern "C" 14 | { 15 | #endif 16 | #ifdef AWSS_SUPPORT_APLIST 17 | struct ap_info { 18 | uint8_t auth; 19 | uint8_t channel; 20 | uint8_t encry[2]; 21 | uint8_t mac[ETH_ALEN]; 22 | char ssid[ZC_MAX_SSID_LEN]; 23 | signed char rssi; 24 | }; 25 | 26 | void aws_try_adjust_chan(void); 27 | 28 | int awss_clear_aplist(void); 29 | int awss_is_ready_clr_aplist(void); 30 | int awss_open_aplist_monitor(void); 31 | int awss_close_aplist_monitor(void); 32 | int awss_init_ieee80211_aplist(void); 33 | int awss_deinit_ieee80211_aplist(void); 34 | int awss_get_auth_info(uint8_t *ssid, uint8_t *bssid, uint8_t *auth, 35 | uint8_t *encry, uint8_t *channel); 36 | int awss_ieee80211_aplist_process(uint8_t *mgmt_header, int len, int link_type, 37 | struct parser_res *res, signed char rssi); 38 | int awss_save_apinfo(uint8_t *ssid, uint8_t* bssid, uint8_t channel, uint8_t auth, 39 | uint8_t pairwise_cipher, uint8_t group_cipher, signed char rssi); 40 | 41 | /* storage to store apinfo */ 42 | extern struct ap_info *zconfig_aplist; 43 | /* aplist num, less than MAX_APLIST_NUM */ 44 | extern uint8_t zconfig_aplist_num; 45 | #endif 46 | 47 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 48 | } 49 | #endif 50 | #endif 51 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/frameworks/awss_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_MAIN_H__ 6 | #define __AWSS_MAIN_H__ 7 | 8 | #include "awss_log.h" 9 | 10 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #define DEFAULT_SSID zc_default_ssid 16 | #define DEFAULT_PASSWD zc_default_passwd 17 | #define ADHA_SSID zc_adha_ssid 18 | #define ADHA_PASSWD zc_adha_passwd 19 | 20 | extern const char *zc_default_ssid; 21 | extern const char *zc_default_passwd; 22 | extern const char *zc_adha_ssid; 23 | extern const char *zc_adha_passwd; 24 | 25 | int __awss_start(void); 26 | int __awss_stop(void); 27 | 28 | int awss_cancel_aha_monitor(void); 29 | 30 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/frameworks/awss_smartconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_SMARTCONFIG_H__ 6 | #define __AWSS_SMARTCONFIG_H__ 7 | 8 | #include 9 | #include "os.h" 10 | #include "zconfig_lib.h" 11 | #include "zconfig_ieee80211.h" 12 | #include "zconfig_protocol.h" 13 | 14 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 15 | extern "C" 16 | { 17 | #endif 18 | 19 | /* invalid channel, neither 0, 0xff, nor 1-13 */ 20 | #define INVALID_CHANNEL (0) 21 | #define PAYLOAD_BITS_CNT (7) 22 | #define PAYLOAD_BITS_MASK ((1 << PAYLOAD_BITS_CNT) - 1) 23 | 24 | extern const uint8_t zconfig_fixed_offset[ZC_ENC_TYPE_MAX + 1][2]; 25 | extern const uint16_t zconfig_hint_frame[]; 26 | 27 | uint8_t is_data_frame(uint16_t len); 28 | uint8_t is_start_frame(uint16_t len); 29 | uint8_t is_group_frame(uint16_t len); 30 | uint8_t get_data_index(uint16_t len); 31 | uint8_t get_group_index(uint16_t len); 32 | 33 | int zconfig_recv_completed(uint8_t tods); 34 | int zconfig_get_ssid_passwd(uint8_t tods); 35 | int package_cmp(uint8_t *package, uint8_t *src, uint8_t *dst, uint8_t tods, uint16_t len); 36 | int package_save(uint8_t *package, uint8_t *src, uint8_t *dst, uint8_t tods, uint16_t len); 37 | int awss_recv_callback_smartconfig(struct parser_res *res); 38 | int awss_ieee80211_smartconfig_process(uint8_t *ieee80211, int len, int link_type, 39 | struct parser_res *res, signed char rssi); 40 | 41 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 42 | } 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/frameworks/utils/awss_crypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_CRYPT_H__ 6 | #define __AWSS_CRYPT_H__ 7 | 8 | enum { 9 | SEC_LVL_OPEN = 0, /* open */ 10 | SEC_LVL_AES256, /* AES256 */ 11 | SEC_LVL_AES128_DEFAULT, /* AES128 with default key */ 12 | SEC_LVL_AES128_PRODUCT, /* AES128 with key from product_sec */ 13 | SEC_LVL_AES128_DEVICE, /* AES128 with key from device_sec */ 14 | SEC_LVL_AES128_MANU, /* AES128 with key from manufacturer_sec */ 15 | }; 16 | 17 | int aes_decrypt_string(char *cipher, char *plain, int len, int cipher_hex, int sec_lvl, char cbc, const char *rand); 18 | 19 | int awss_get_encrypt_type(); 20 | #endif 21 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/frameworks/utils/zconfig_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __ZCONFIG_UTILS_H__ 6 | #define __ZCONFIG_UTILS_H__ 7 | 8 | #include "os.h" 9 | 10 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 11 | extern "C" 12 | { 13 | #endif 14 | 15 | void dump_mac(uint8_t *src, uint8_t *dst); 16 | void dump_hex(uint8_t *data, int len, int tab_num); 17 | void dump_ascii(uint8_t *data, int len, int tab_num); 18 | 19 | uint16_t zconfig_checksum_v3(uint8_t *data, uint8_t len); 20 | char is_utf8(const char *ansi_str, int length); 21 | 22 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/p2p/awss_wps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_WPS_H__ 6 | #define __AWSS_WPS_H__ 7 | 8 | #ifdef AWSS_SUPPORT_SMARTCONFIG_WPS 9 | 10 | #include 11 | #include "os.h" 12 | #include "zconfig_ieee80211.h" 13 | 14 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #define WLAN_OUI_MICROSOFT (0x0050F2) 20 | #define WLAN_OUI_WPS (0x0050F2) 21 | #define WLAN_OUI_TYPE_MICROSOFT_WPA (1) 22 | #define WLAN_OUI_TYPE_WPS (4) 23 | 24 | int awss_recv_callback_wps(struct parser_res *res); 25 | int awss_ieee80211_wps_process(uint8_t *mgmt_header, int len, int link_type, 26 | struct parser_res *res, signed char rssi); 27 | 28 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 29 | } 30 | #endif 31 | #endif /* end AWSS_SUPPORT_SMARTCONFIG_WPS */ 32 | #endif 33 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/phone_ap/awss_aha.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_AHA_H__ 6 | #define __AWSS_AHA_H__ 7 | 8 | #include 9 | #include "os.h" 10 | #include "zconfig_ieee80211.h" 11 | 12 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 13 | extern "C" 14 | { 15 | #endif 16 | 17 | int awss_open_aha_monitor(void); 18 | int awss_close_aha_monitor(void); 19 | int awss_aha_monitor_is_timeout(void); 20 | int aws_send_aha_probe_req(void); 21 | int awss_recv_callback_aha_ssid(struct parser_res *res); 22 | int awss_ieee80211_aha_process(uint8_t *mgmt_header, int len, int link_type, struct parser_res *res, signed char rssi); 23 | 24 | extern const char *zc_default_ssid; 25 | extern const char *zc_default_passwd; 26 | 27 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 28 | } 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/phone_ap/awss_wifimgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_WIFIMGR_H__ 6 | #define __AWSS_WIFIMGR_H__ 7 | 8 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #if defined(AWSS_SUPPORT_ADHA) || defined(AWSS_SUPPORT_AHA) 14 | 15 | enum { 16 | SHUB_ERR, 17 | SHUB_OK 18 | }; 19 | 20 | int wifimgr_process_get_wifilist_request(void *ctx, void *resource, void *remote, void *request); 21 | int wifimgr_process_mcast_get_device_info(void *ctx, void *resource, void *remote, void *request); 22 | int wifimgr_process_ucast_get_device_info(void *ctx, void *resource, void *remote, void *request); 23 | int wifimgr_process_switch_ap_request(void *ctx, void *resource, void *remote, void *request); 24 | 25 | #endif 26 | 27 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/router_ap/awss_adha.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AWSS_ADHA_H__ 6 | #define __AWSS_ADHA_H__ 7 | 8 | #if defined(AWSS_SUPPORT_ADHA) || defined(AWSS_SUPPORT_AHA) 9 | 10 | #include "zconfig_lib.h" 11 | #include "zconfig_protocol.h" 12 | 13 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 14 | extern "C" 15 | { 16 | #endif 17 | 18 | struct adha_info { 19 | uint8_t try_idx; 20 | uint8_t cnt; 21 | uint8_t aplist[MAX_APLIST_NUM]; 22 | }; 23 | 24 | int awss_init_adha_aplist(void); 25 | int awss_deinit_adha_aplist(void); 26 | extern struct adha_info *adha_aplist; 27 | extern const char *zc_adha_passwd; 28 | extern const char *zc_adha_ssid; 29 | 30 | #ifdef AWSS_SUPPORT_ADHA 31 | int awss_open_adha_monitor(void); 32 | int awss_close_adha_monitor(void); 33 | int aws_send_adha_probe_req(void); 34 | 35 | int awss_is_ready_switch_next_adha(void); 36 | int awss_recv_callback_adha_ssid(struct parser_res *res); 37 | int awss_ieee80211_adha_process(uint8_t *mgmt_header, int len, int link_type, 38 | struct parser_res *res, signed char rssi); 39 | #endif 40 | 41 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 42 | } 43 | #endif 44 | #endif /* end AWSS_SUPPORT_ADHA || AWSS_SUPPORT_AHA */ 45 | #endif 46 | -------------------------------------------------------------------------------- /iotkit-embedded/wifi_provision/wifi_provision_internal.h: -------------------------------------------------------------------------------- 1 | #include "infra_config.h" 2 | #include 3 | #include 4 | #include "aws_lib.h" 5 | #include "awss_aplist.h" 6 | #include "zconfig_lib.h" 7 | #include "zconfig_utils.h" 8 | #include "zconfig_protocol.h" 9 | #include "zconfig_ieee80211.h" 10 | #include "awss_event.h" 11 | #include "awss_timer.h" 12 | #include "awss_main.h" 13 | #include "iot_import_awss.h" 14 | #include "os.h" 15 | #include "infra_compat.h" 16 | #include "awss_smartconfig.h" 17 | #include "infra_sha1.h" 18 | #include "passwd.h" 19 | #include "awss_utils.h" 20 | #include "awss_statis.h" 21 | #include "awss_packet.h" 22 | #include "awss_notify.h" 23 | #include "awss_cmp.h" 24 | #include "wifi_provision_api.h" 25 | #include "awss_cmp.h" 26 | #include "awss_crypt.h" 27 | #include "sha256.h" 28 | #include 29 | #include "infra_json_parser.h" 30 | #include "mqtt_api.h" 31 | #include "awss_dev_reset_internal.h" 32 | #include "awss_info.h" 33 | 34 | #include "awss_bind_statis.h" 35 | #include "dev_bind_wrapper.h" 36 | #include "awss_aplist.h" 37 | 38 | #ifdef AWSS_SUPPORT_SMARTCONFIG_WPS 39 | #include "awss_wps.h" 40 | #endif 41 | 42 | #ifdef AWSS_SUPPORT_HT40 43 | #include "awss_ht40.h" 44 | #endif 45 | 46 | #if defined(AWSS_SUPPORT_AHA) || defined(AWSS_SUPPORT_ADHA) 47 | #include "awss_wifimgr.h" 48 | #endif 49 | 50 | #ifndef AWSS_DISABLE_ENROLLEE 51 | #include "awss_enrollee.h" 52 | #endif 53 | 54 | #if defined(AWSS_SUPPORT_AHA) 55 | #include "awss_aha.h" 56 | #endif 57 | #if defined(AWSS_SUPPORT_ADHA) 58 | #include "awss_adha.h" 59 | #endif 60 | 61 | #if defined(WIFI_PROVISION_ENABLED) || defined(DEV_BIND_ENABLED) 62 | #include "coap_api.h" 63 | #include "iotx_coap.h" 64 | #endif 65 | 66 | #ifdef AWSS_SUPPORT_SMARTCONFIG_WPS 67 | #include "p2p_wrapper.h" 68 | #endif 69 | 70 | #ifdef AWSS_SUPPORT_SMARTCONFIG 71 | #include "smartconfig_wrapper.h" 72 | #endif 73 | 74 | #ifdef AWSS_SUPPORT_ZEROCONFIG 75 | #include "zeroconfig_wrapper.h" 76 | #endif 77 | 78 | #ifdef AWSS_SUPPORT_AHA 79 | #include "aha_wrapper.h" 80 | #endif 81 | 82 | #ifdef AWSS_SUPPORT_DEV_AP 83 | #include "dev_ap_wrapper.h" 84 | #endif 85 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #include "nghttp2_debug.h" 7 | 8 | #include 9 | 10 | #ifdef DEBUGBUILD 11 | 12 | static void nghttp2_default_debug_vfprintf_callback(const char *fmt, 13 | va_list args) { 14 | vfprintf(stderr, fmt, args); 15 | } 16 | 17 | static nghttp2_debug_vprintf_callback static_debug_vprintf_callback = 18 | nghttp2_default_debug_vfprintf_callback; 19 | 20 | void nghttp2_debug_vprintf(const char *format, ...) { 21 | if (static_debug_vprintf_callback) { 22 | va_list args; 23 | va_start(args, format); 24 | static_debug_vprintf_callback(format, args); 25 | va_end(args); 26 | } 27 | } 28 | 29 | void nghttp2_set_debug_vprintf_callback( 30 | nghttp2_debug_vprintf_callback debug_vprintf_callback) { 31 | static_debug_vprintf_callback = debug_vprintf_callback; 32 | } 33 | 34 | #else /* !DEBUGBUILD */ 35 | 36 | void nghttp2_set_debug_vprintf_callback( 37 | nghttp2_debug_vprintf_callback debug_vprintf_callback) { 38 | (void)debug_vprintf_callback; 39 | } 40 | 41 | #endif /* !DEBUGBUILD */ 42 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_DEBUG_H 7 | #define NGHTTP2_DEBUG_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | #ifdef DEBUGBUILD 16 | #define DEBUGF(...) nghttp2_debug_vprintf(__VA_ARGS__) 17 | void nghttp2_debug_vprintf(const char *format, ...); 18 | #else 19 | #define DEBUGF(...) \ 20 | do { \ 21 | } while (0) 22 | #endif 23 | 24 | #endif /* NGHTTP2_DEBUG_H */ 25 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_hd_huffman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_HD_HUFFMAN_H 7 | #define NGHTTP2_HD_HUFFMAN_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | typedef enum { 16 | /* FSA accepts this state as the end of huffman encoding 17 | sequence. */ 18 | NGHTTP2_HUFF_ACCEPTED = 1, 19 | /* This state emits symbol */ 20 | NGHTTP2_HUFF_SYM = (1 << 1), 21 | /* If state machine reaches this state, decoding fails. */ 22 | NGHTTP2_HUFF_FAIL = (1 << 2) 23 | } nghttp2_huff_decode_flag; 24 | 25 | typedef struct { 26 | /* huffman decoding state, which is actually the node ID of internal 27 | huffman tree. We have 257 leaf nodes, but they are identical to 28 | root node other than emitting a symbol, so we have 256 internal 29 | nodes [1..255], inclusive. */ 30 | uint8_t state; 31 | /* bitwise OR of zero or more of the nghttp2_huff_decode_flag */ 32 | uint8_t flags; 33 | /* symbol if NGHTTP2_HUFF_SYM flag set */ 34 | uint8_t sym; 35 | } nghttp2_huff_decode; 36 | 37 | typedef nghttp2_huff_decode huff_decode_table_type[16]; 38 | 39 | typedef struct { 40 | /* Current huffman decoding state. We stripped leaf nodes, so the 41 | value range is [0..255], inclusive. */ 42 | uint8_t state; 43 | /* nonzero if we can say that the decoding process succeeds at this 44 | state */ 45 | uint8_t accept; 46 | } nghttp2_hd_huff_decode_context; 47 | 48 | typedef struct { 49 | /* The number of bits in this code */ 50 | uint32_t nbits; 51 | /* Huffman code aligned to LSB */ 52 | uint32_t code; 53 | } nghttp2_huff_sym; 54 | 55 | extern const nghttp2_huff_sym huff_sym_table[]; 56 | extern const nghttp2_huff_decode huff_decode_table[][16]; 57 | 58 | #endif /* NGHTTP2_HD_HUFFMAN_H */ 59 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_INT_H 7 | #define NGHTTP2_INT_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | /* Macros, types and constants for internal use */ 16 | 17 | /* "less" function, return nonzero if |lhs| is less than |rhs|. */ 18 | typedef int (*nghttp2_less)(const void *lhs, const void *rhs); 19 | 20 | /* Internal error code. They must be in the range [-499, -100], 21 | inclusive. */ 22 | typedef enum { 23 | NGHTTP2_ERR_CREDENTIAL_PENDING = -101, 24 | NGHTTP2_ERR_IGN_HEADER_BLOCK = -103, 25 | NGHTTP2_ERR_IGN_PAYLOAD = -104, 26 | /* 27 | * Invalid HTTP header field was received but it can be treated as 28 | * if it was not received because of compatibility reasons. 29 | */ 30 | NGHTTP2_ERR_IGN_HTTP_HEADER = -105, 31 | /* 32 | * Invalid HTTP header field was received, and it is ignored. 33 | * Unlike NGHTTP2_ERR_IGN_HTTP_HEADER, this does not invoke 34 | * nghttp2_on_invalid_header_callback. 35 | */ 36 | NGHTTP2_ERR_REMOVE_HTTP_HEADER = -106 37 | } nghttp2_internal_error; 38 | 39 | #endif /* NGHTTP2_INT_H */ 40 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "nghttp2_mem.h" 7 | #ifdef INFRA_MEM_STATS 8 | #include "infra_mem_stats.h" 9 | #endif 10 | 11 | extern void *HAL_Malloc(uint32_t size); 12 | extern void *HAL_Realloc(void *ptr, uint32_t size); 13 | extern void HAL_Free(void *ptr); 14 | 15 | 16 | static void *default_malloc(size_t size, void *mem_user_data) 17 | { 18 | (void)mem_user_data; 19 | 20 | #ifdef INFRA_MEM_STATS 21 | return LITE_malloc(size, MEM_MAGIC, "nghttp2"); 22 | #else 23 | return HAL_Malloc(size); 24 | #endif 25 | } 26 | 27 | static void default_free(void *ptr, void *mem_user_data) 28 | { 29 | (void)mem_user_data; 30 | if (ptr != NULL) { 31 | #ifdef INFRA_MEM_STATS 32 | LITE_free(ptr); 33 | #else 34 | HAL_Free((void *)ptr); 35 | ptr = NULL; 36 | #endif 37 | } 38 | } 39 | 40 | static void *default_calloc(size_t nmemb, size_t size, void *mem_user_data) 41 | { 42 | /* (void)mem_user_data; */ 43 | 44 | #ifdef INFRA_MEM_STATS 45 | return LITE_calloc(nmemb, size, MEM_MAGIC, "nghttp2"); 46 | #else 47 | void *ptr = HAL_Malloc(nmemb * size); 48 | if (ptr != NULL) { 49 | memset(ptr, 0, nmemb * size); 50 | } 51 | return ptr; 52 | #endif 53 | } 54 | 55 | static void *default_realloc(void *ptr, size_t size, void *mem_user_data) 56 | { 57 | (void)mem_user_data; 58 | 59 | #ifdef INFRA_MEM_STATS 60 | return LITE_realloc(ptr, size, MEM_MAGIC, "nghttp2"); 61 | #else 62 | return HAL_Realloc(ptr, size); 63 | #endif 64 | } 65 | 66 | static nghttp2_mem mem_default = {NULL, default_malloc, default_free, 67 | default_calloc, default_realloc 68 | }; 69 | 70 | nghttp2_mem *nghttp2_mem_default(void) 71 | { 72 | return &mem_default; 73 | } 74 | 75 | void *nghttp2_mem_malloc(nghttp2_mem *mem, size_t size) 76 | { 77 | return mem->malloc(size, mem->mem_user_data); 78 | } 79 | 80 | void nghttp2_mem_free(nghttp2_mem *mem, void *ptr) 81 | { 82 | mem->free(ptr, mem->mem_user_data); 83 | } 84 | 85 | void nghttp2_mem_free2(nghttp2_free free_func, void *ptr, void *mem_user_data) 86 | { 87 | free_func(ptr, mem_user_data); 88 | } 89 | 90 | void *nghttp2_mem_calloc(nghttp2_mem *mem, size_t nmemb, size_t size) 91 | { 92 | return mem->calloc(nmemb, size, mem->mem_user_data); 93 | } 94 | 95 | void *nghttp2_mem_realloc(nghttp2_mem *mem, void *ptr, size_t size) 96 | { 97 | return mem->realloc(ptr, size, mem->mem_user_data); 98 | } 99 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_MEM_H 7 | #define NGHTTP2_MEM_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | #ifdef INFRA_MEM_STATS 15 | #include "infra_mem_stats.h" 16 | #endif 17 | 18 | /* The default, system standard memory allocator */ 19 | nghttp2_mem *nghttp2_mem_default(void); 20 | 21 | /* Convenient wrapper functions to call allocator function in 22 | |mem|. */ 23 | void *nghttp2_mem_malloc(nghttp2_mem *mem, size_t size); 24 | void nghttp2_mem_free(nghttp2_mem *mem, void *ptr); 25 | void nghttp2_mem_free2(nghttp2_free free_func, void *ptr, void *mem_user_data); 26 | void *nghttp2_mem_calloc(nghttp2_mem *mem, size_t nmemb, size_t size); 27 | void *nghttp2_mem_realloc(nghttp2_mem *mem, void *ptr, size_t size); 28 | 29 | #endif /* NGHTTP2_MEM_H */ 30 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_net.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #include 7 | #include 8 | #include "nghttp2_net.h" 9 | 10 | #if IOT_BYTE_ORDER == LITTLE_ENDIAN 11 | uint32_t nghttp2_htonl(uint32_t hostlong) { 12 | uint32_t res; 13 | unsigned char *p = (unsigned char *)&res; 14 | *p++ = hostlong >> 24; 15 | *p++ = (hostlong >> 16) & 0xffu; 16 | *p++ = (hostlong >> 8) & 0xffu; 17 | *p = hostlong & 0xffu; 18 | return res; 19 | } 20 | 21 | uint16_t nghttp2_htons(uint16_t hostshort) { 22 | uint16_t res; 23 | unsigned char *p = (unsigned char *)&res; 24 | *p++ = hostshort >> 8; 25 | *p = hostshort & 0xffu; 26 | return res; 27 | } 28 | 29 | uint32_t nghttp2_ntohl(uint32_t netlong) { 30 | uint32_t res; 31 | unsigned char *p = (unsigned char *)&netlong; 32 | res = *p++ << 24; 33 | res += *p++ << 16; 34 | res += *p++ << 8; 35 | res += *p; 36 | return res; 37 | } 38 | 39 | uint16_t nghttp2_ntohs(uint16_t netshort) { 40 | uint16_t res; 41 | unsigned char *p = (unsigned char *)&netshort; 42 | res = *p++ << 8; 43 | res += *p; 44 | return res; 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_NET_H 7 | #define NGHTTP2_NET_H 8 | 9 | #ifndef LITTLE_ENDIAN 10 | #define LITTLE_ENDIAN 1234 11 | #endif 12 | 13 | #ifndef BIG_ENDIAN 14 | #define BIG_ENDIAN 4321 15 | #endif 16 | 17 | #define IOT_BYTE_ORDER LITTLE_ENDIAN 18 | 19 | #if IOT_BYTE_ORDER == BIG_ENDIAN 20 | #define nghttp2_htonl(x) (x) 21 | #define nghttp2_htons(x) (x) 22 | #define nghttp2_ntohl(x) (x) 23 | #define nghttp2_ntohs(x) (x) 24 | #else 25 | /* Windows requires ws2_32 library for ntonl family functions. We 26 | define inline functions for those function so that we don't have 27 | dependeny on that lib. */ 28 | 29 | #ifdef _MSC_VER 30 | #define STIN 31 | #else 32 | #define STIN 33 | #endif 34 | 35 | STIN uint32_t nghttp2_htonl(uint32_t hostlong); 36 | 37 | STIN uint16_t nghttp2_htons(uint16_t hostshort); 38 | 39 | STIN uint32_t nghttp2_ntohl(uint32_t netlong); 40 | 41 | STIN uint16_t nghttp2_ntohs(uint16_t netshort); 42 | 43 | #endif 44 | #endif /* NGHTTP2_NET_H */ 45 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_npn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #include "nghttp2_npn.h" 7 | 8 | #include 9 | 10 | static int select_next_protocol(unsigned char **out, unsigned char *outlen, 11 | const unsigned char *in, unsigned int inlen, 12 | const char *key, unsigned int keylen) { 13 | unsigned int i; 14 | for (i = 0; i + keylen <= inlen; i += (unsigned int)(in[i] + 1)) { 15 | if (memcmp(&in[i], key, keylen) == 0) { 16 | *out = (unsigned char *)&in[i + 1]; 17 | *outlen = in[i]; 18 | return 0; 19 | } 20 | } 21 | return -1; 22 | } 23 | 24 | #define NGHTTP2_HTTP_1_1_ALPN "\x8http/1.1" 25 | #define NGHTTP2_HTTP_1_1_ALPN_LEN (sizeof(NGHTTP2_HTTP_1_1_ALPN) - 1) 26 | 27 | int nghttp2_select_next_protocol(unsigned char **out, unsigned char *outlen, 28 | const unsigned char *in, unsigned int inlen) { 29 | if (select_next_protocol(out, outlen, in, inlen, NGHTTP2_PROTO_ALPN, 30 | NGHTTP2_PROTO_ALPN_LEN) == 0) { 31 | return 1; 32 | } 33 | if (select_next_protocol(out, outlen, in, inlen, NGHTTP2_HTTP_1_1_ALPN, 34 | NGHTTP2_HTTP_1_1_ALPN_LEN) == 0) { 35 | return 0; 36 | } 37 | return -1; 38 | } 39 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_npn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_NPN_H 7 | #define NGHTTP2_NPN_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | #endif /* NGHTTP2_NPN_H */ 16 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_priority_spec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #include "nghttp2_priority_spec.h" 7 | 8 | void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec, 9 | int32_t stream_id, int32_t weight, 10 | int exclusive) { 11 | pri_spec->stream_id = stream_id; 12 | pri_spec->weight = weight; 13 | pri_spec->exclusive = exclusive != 0; 14 | } 15 | 16 | void nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec) { 17 | pri_spec->stream_id = 0; 18 | pri_spec->weight = NGHTTP2_DEFAULT_WEIGHT; 19 | pri_spec->exclusive = 0; 20 | } 21 | 22 | int nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec) { 23 | return pri_spec->stream_id == 0 && 24 | pri_spec->weight == NGHTTP2_DEFAULT_WEIGHT && pri_spec->exclusive == 0; 25 | } 26 | 27 | void nghttp2_priority_spec_normalize_weight(nghttp2_priority_spec *pri_spec) { 28 | if (pri_spec->weight < NGHTTP2_MIN_WEIGHT) { 29 | pri_spec->weight = NGHTTP2_MIN_WEIGHT; 30 | } else if (pri_spec->weight > NGHTTP2_MAX_WEIGHT) { 31 | pri_spec->weight = NGHTTP2_MAX_WEIGHT; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_priority_spec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_PRIORITY_SPEC_H 7 | #define NGHTTP2_PRIORITY_SPEC_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | /* 16 | * This function normalizes pri_spec->weight if it is out of range. 17 | * If pri_spec->weight is less than NGHTTP2_MIN_WEIGHT, it is set to 18 | * NGHTTP2_MIN_WEIGHT. If pri_spec->weight is larger than 19 | * NGHTTP2_MAX_WEIGHT, it is set to NGHTTP2_MAX_WEIGHT. 20 | */ 21 | void nghttp2_priority_spec_normalize_weight(nghttp2_priority_spec *pri_spec); 22 | 23 | #endif /* NGHTTP2_PRIORITY_SPEC_H */ 24 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_queue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "nghttp2_queue.h" 6 | 7 | #include 8 | #include 9 | #ifdef INFRA_MEM_STATS 10 | #include "infra_mem_stats.h" 11 | #endif 12 | 13 | extern void *HAL_Malloc(uint32_t size); 14 | extern void *HAL_Realloc(void *ptr, uint32_t size); 15 | extern void HAL_Free(void *ptr); 16 | 17 | #if INFRA_MEM_STATS 18 | #define NGHTTP2_QUEUE_MALLOC(size) LITE_malloc(size, MEM_MAGIC, "nghttp2.queue") 19 | #define NGHTTP2_QUEUE_FREE(ptr) LITE_free(ptr) 20 | #else 21 | #define NGHTTP2_QUEUE_MALLOC(size) HAL_Malloc(size) 22 | #define NGHTTP2_QUEUE_FREE(ptr) {HAL_Free((void *)ptr);ptr = NULL;} 23 | #endif 24 | 25 | void nghttp2_queue_init(nghttp2_queue *queue) { 26 | queue->front = queue->back = NULL; 27 | } 28 | 29 | void nghttp2_queue_free(nghttp2_queue *queue) { 30 | if (!queue) { 31 | return; 32 | } else { 33 | nghttp2_queue_cell *p = queue->front; 34 | while (p) { 35 | nghttp2_queue_cell *next = p->next; 36 | NGHTTP2_QUEUE_FREE(p); 37 | p = next; 38 | } 39 | } 40 | } 41 | 42 | int nghttp2_queue_push(nghttp2_queue *queue, void *data) { 43 | nghttp2_queue_cell *new_cell = 44 | (nghttp2_queue_cell *)NGHTTP2_QUEUE_MALLOC(sizeof(nghttp2_queue_cell)); 45 | if (!new_cell) { 46 | return NGHTTP2_ERR_NOMEM; 47 | } 48 | new_cell->data = data; 49 | new_cell->next = NULL; 50 | if (queue->back) { 51 | queue->back->next = new_cell; 52 | queue->back = new_cell; 53 | 54 | } else { 55 | queue->front = queue->back = new_cell; 56 | } 57 | return 0; 58 | } 59 | 60 | void nghttp2_queue_pop(nghttp2_queue *queue) { 61 | nghttp2_queue_cell *front = queue->front; 62 | assert(front); 63 | queue->front = front->next; 64 | if (front == queue->back) { 65 | queue->back = NULL; 66 | } 67 | NGHTTP2_QUEUE_FREE(front); 68 | } 69 | 70 | void *nghttp2_queue_front(nghttp2_queue *queue) { 71 | assert(queue->front); 72 | return queue->front->data; 73 | } 74 | 75 | void *nghttp2_queue_back(nghttp2_queue *queue) { 76 | assert(queue->back); 77 | return queue->back->data; 78 | } 79 | 80 | int nghttp2_queue_empty(nghttp2_queue *queue) { return queue->front == NULL; } 81 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_QUEUE_H 7 | #define NGHTTP2_QUEUE_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include "config.h" 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | typedef struct nghttp2_queue_cell { 16 | void *data; 17 | struct nghttp2_queue_cell *next; 18 | } nghttp2_queue_cell; 19 | 20 | typedef struct { 21 | nghttp2_queue_cell *front, *back; 22 | } nghttp2_queue; 23 | 24 | void nghttp2_queue_init(nghttp2_queue *queue); 25 | void nghttp2_queue_free(nghttp2_queue *queue); 26 | int nghttp2_queue_push(nghttp2_queue *queue, void *data); 27 | void nghttp2_queue_pop(nghttp2_queue *queue); 28 | void *nghttp2_queue_front(nghttp2_queue *queue); 29 | void *nghttp2_queue_back(nghttp2_queue *queue); 30 | int nghttp2_queue_empty(nghttp2_queue *queue); 31 | 32 | #endif /* NGHTTP2_QUEUE_H */ 33 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_rcbuf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #include "nghttp2_rcbuf.h" 7 | 8 | #include 9 | #include 10 | 11 | #include "nghttp2_mem.h" 12 | #include "nghttp2_helper.h" 13 | 14 | int nghttp2_rcbuf_new(nghttp2_rcbuf **rcbuf_ptr, size_t size, 15 | nghttp2_mem *mem) { 16 | uint8_t *p; 17 | 18 | p = nghttp2_mem_malloc(mem, sizeof(nghttp2_rcbuf) + size); 19 | if (p == NULL) { 20 | return NGHTTP2_ERR_NOMEM; 21 | } 22 | 23 | *rcbuf_ptr = (void *)p; 24 | 25 | (*rcbuf_ptr)->mem_user_data = mem->mem_user_data; 26 | (*rcbuf_ptr)->free = mem->free; 27 | (*rcbuf_ptr)->base = p + sizeof(nghttp2_rcbuf); 28 | (*rcbuf_ptr)->len = size; 29 | (*rcbuf_ptr)->ref = 1; 30 | 31 | return 0; 32 | } 33 | 34 | int nghttp2_rcbuf_new2(nghttp2_rcbuf **rcbuf_ptr, const uint8_t *src, 35 | size_t srclen, nghttp2_mem *mem) { 36 | int rv; 37 | 38 | rv = nghttp2_rcbuf_new(rcbuf_ptr, srclen + 1, mem); 39 | if (rv != 0) { 40 | return rv; 41 | } 42 | 43 | (*rcbuf_ptr)->len = srclen; 44 | *nghttp2_cpymem((*rcbuf_ptr)->base, src, srclen) = '\0'; 45 | 46 | return 0; 47 | } 48 | 49 | /* 50 | * Frees |rcbuf| itself, regardless of its reference cout. 51 | */ 52 | void nghttp2_rcbuf_del(nghttp2_rcbuf *rcbuf) { 53 | nghttp2_mem_free2(rcbuf->free, rcbuf, rcbuf->mem_user_data); 54 | } 55 | 56 | void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf) { 57 | if (rcbuf->ref == -1) { 58 | return; 59 | } 60 | 61 | ++rcbuf->ref; 62 | } 63 | 64 | void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf) { 65 | if (rcbuf == NULL || rcbuf->ref == -1) { 66 | return; 67 | } 68 | 69 | assert(rcbuf->ref > 0); 70 | 71 | if (--rcbuf->ref == 0) { 72 | nghttp2_rcbuf_del(rcbuf); 73 | } 74 | } 75 | 76 | nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf) { 77 | nghttp2_vec res = {rcbuf->base, rcbuf->len}; 78 | return res; 79 | } 80 | 81 | int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf) { 82 | return rcbuf->ref == -1; 83 | } 84 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_rcbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_RCBUF_H 7 | #define NGHTTP2_RCBUF_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | struct nghttp2_rcbuf { 16 | /* custom memory allocator belongs to the mem parameter when 17 | creating this object. */ 18 | void *mem_user_data; 19 | nghttp2_free free; 20 | /* The pointer to the underlying buffer */ 21 | uint8_t *base; 22 | /* Size of buffer pointed by |base|. */ 23 | size_t len; 24 | /* Reference count */ 25 | int32_t ref; 26 | }; 27 | 28 | /* 29 | * Allocates nghttp2_rcbuf object with |size| as initial buffer size. 30 | * When the function succeeds, the reference count becomes 1. 31 | * 32 | * This function returns 0 if it succeeds, or one of the following 33 | * negative error codes: 34 | * 35 | * NGHTTP2_ERR_NOMEM: 36 | * Out of memory. 37 | */ 38 | int nghttp2_rcbuf_new(nghttp2_rcbuf **rcbuf_ptr, size_t size, nghttp2_mem *mem); 39 | 40 | /* 41 | * Like nghttp2_rcbuf_new(), but initializes the buffer with |src| of 42 | * length |srclen|. This function allocates additional byte at the 43 | * end and puts '\0' into it, so that the resulting buffer could be 44 | * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to 45 | * |srclen|. 46 | * 47 | * This function returns 0 if it succeeds, or one of the following 48 | * negative error codes: 49 | * 50 | * NGHTTP2_ERR_NOMEM: 51 | * Out of memory. 52 | */ 53 | int nghttp2_rcbuf_new2(nghttp2_rcbuf **rcbuf_ptr, const uint8_t *src, 54 | size_t srclen, nghttp2_mem *mem); 55 | 56 | /* 57 | * Frees |rcbuf| itself, regardless of its reference cout. 58 | */ 59 | void nghttp2_rcbuf_del(nghttp2_rcbuf *rcbuf); 60 | 61 | #endif /* NGHTTP2_RCBUF_H */ 62 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_submit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2_SUBMIT_H 7 | #define NGHTTP2_SUBMIT_H 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif /* HAVE_CONFIG_H */ 12 | 13 | #include "nghttp2.h" 14 | 15 | #endif /* NGHTTP2_SUBMIT_H */ 16 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2_version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifdef HAVE_CONFIG_H 7 | #include 8 | #endif /* HAVE_CONFIG_H */ 9 | 10 | #include "nghttp2.h" 11 | 12 | static nghttp2_info version = {NGHTTP2_VERSION_AGE, NGHTTP2_VERSION_NUM, 13 | NGHTTP2_VERSION, NGHTTP2_PROTO_VERSION_ID}; 14 | 15 | nghttp2_info *nghttp2_version(int least_version) { 16 | if (least_version > NGHTTP2_VERSION_NUM) 17 | return NULL; 18 | return &version; 19 | } 20 | -------------------------------------------------------------------------------- /wrappers/external_libs/nghttp2/nghttp2ver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NGHTTP2VER_H 7 | #define NGHTTP2VER_H 8 | 9 | /** 10 | * @macro 11 | * Version number of the nghttp2 library release 12 | */ 13 | #define NGHTTP2_VERSION "nghttp2" 14 | 15 | /** 16 | * @macro 17 | * Numerical representation of the version number of the nghttp2 library 18 | * release. This is a 24 bit number with 8 bits for major number, 8 bits 19 | * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203. 20 | */ 21 | #define NGHTTP2_VERSION_NUM 0x013190 22 | 23 | #endif /* NGHTTP2VER_H */ 24 | -------------------------------------------------------------------------------- /wrappers/wrappers_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef _WRAPPERS_DEFS_H_ 2 | #define _WRAPPERS_DEFS_H_ 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | 7 | #define PLATFORM_WAIT_INFINITE (~0) 8 | 9 | typedef struct { 10 | void *(*malloc)(uint32_t size); 11 | void (*free)(void *ptr); 12 | } ssl_hooks_t; 13 | 14 | typedef enum { 15 | os_thread_priority_idle = -3, /* priority: idle (lowest) */ 16 | os_thread_priority_low = -2, /* priority: low */ 17 | os_thread_priority_belowNormal = -1, /* priority: below normal */ 18 | os_thread_priority_normal = 0, /* priority: normal (default) */ 19 | os_thread_priority_aboveNormal = 1, /* priority: above normal */ 20 | os_thread_priority_high = 2, /* priority: high */ 21 | os_thread_priority_realtime = 3, /* priority: realtime (highest) */ 22 | os_thread_priority_error = 0x84, /* system cannot determine priority or thread has illegal priority */ 23 | } hal_os_thread_priority_t; 24 | 25 | typedef struct _hal_os_thread { 26 | hal_os_thread_priority_t priority; /*initial thread priority */ 27 | void *stack_addr; /* thread stack address malloced by caller, use system stack by . */ 28 | int stack_size; /* stack size requirements in bytes; 0 is default stack size */ 29 | int detach_state; /* 0: not detached state; otherwise: detached state. */ 30 | char *name; /* thread name. */ 31 | } hal_os_thread_param_t; 32 | 33 | #define DTLS_ERROR_BASE (1<<24) 34 | #define DTLS_SUCCESS (0) 35 | #define DTLS_INVALID_PARAM (DTLS_ERROR_BASE | 1) 36 | #define DTLS_INVALID_CA_CERTIFICATE (DTLS_ERROR_BASE | 2) 37 | #define DTLS_HANDSHAKE_IN_PROGRESS (DTLS_ERROR_BASE | 3) 38 | #define DTLS_HANDSHAKE_FAILED (DTLS_ERROR_BASE | 4) 39 | #define DTLS_FATAL_ALERT_MESSAGE (DTLS_ERROR_BASE | 5) 40 | #define DTLS_PEER_CLOSE_NOTIFY (DTLS_ERROR_BASE | 6) 41 | #define DTLS_SESSION_CREATE_FAILED (DTLS_ERROR_BASE | 7) 42 | #define DTLS_READ_DATA_FAILED (DTLS_ERROR_BASE | 8) 43 | 44 | typedef struct { 45 | void *(*malloc)(uint32_t size); 46 | void (*free)(void *ptr); 47 | } dtls_hooks_t; 48 | 49 | typedef struct { 50 | unsigned char *p_ca_cert_pem; 51 | char *p_host; 52 | unsigned short port; 53 | } coap_dtls_options_t; 54 | 55 | typedef void DTLSContext; 56 | 57 | #endif 58 | 59 | --------------------------------------------------------------------------------